errors.rs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Copyright (c) 2018, The Tor Project, Inc.
  2. // Copyright (c) 2018, isis agora lovecruft
  3. // See LICENSE for licensing information
  4. //! Various errors which may occur during protocol version parsing.
  5. use std::fmt;
  6. use std::fmt::Display;
  7. /// All errors which may occur during protover parsing routines.
  8. #[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
  9. #[allow(missing_docs)] // See Display impl for error descriptions
  10. pub enum ProtoverError {
  11. Overlap,
  12. LowGreaterThanHigh,
  13. Unparseable,
  14. ExceedsMax,
  15. ExceedsExpansionLimit,
  16. UnknownProtocol,
  17. ExceedsNameLimit,
  18. }
  19. /// Descriptive error messages for `ProtoverError` variants.
  20. impl Display for ProtoverError {
  21. fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
  22. match *self {
  23. ProtoverError::Overlap
  24. => write!(f, "Two or more (low, high) protover ranges would overlap once expanded."),
  25. ProtoverError::LowGreaterThanHigh
  26. => write!(f, "The low in a (low, high) protover range was greater than high."),
  27. ProtoverError::Unparseable
  28. => write!(f, "The protover string was unparseable."),
  29. ProtoverError::ExceedsMax
  30. => write!(f, "The high in a (low, high) protover range exceeds u32::MAX."),
  31. ProtoverError::ExceedsExpansionLimit
  32. => write!(f, "The protover string would exceed the maximum expansion limit."),
  33. ProtoverError::UnknownProtocol
  34. => write!(f, "A protocol in the protover string we attempted to parse is unknown."),
  35. ProtoverError::ExceedsNameLimit
  36. => write!(f, "An unrecognised protocol name was too long."),
  37. }
  38. }
  39. }