errors.rs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. InvalidProtocol,
  19. }
  20. /// Descriptive error messages for `ProtoverError` variants.
  21. impl Display for ProtoverError {
  22. fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
  23. match *self {
  24. ProtoverError::Overlap
  25. => write!(f, "Two or more (low, high) protover ranges would overlap once expanded."),
  26. ProtoverError::LowGreaterThanHigh
  27. => write!(f, "The low in a (low, high) protover range was greater than high."),
  28. ProtoverError::Unparseable
  29. => write!(f, "The protover string was unparseable."),
  30. ProtoverError::ExceedsMax
  31. => write!(f, "The high in a (low, high) protover range exceeds u32::MAX."),
  32. ProtoverError::ExceedsExpansionLimit
  33. => write!(f, "The protover string would exceed the maximum expansion limit."),
  34. ProtoverError::UnknownProtocol
  35. => write!(f, "A protocol in the protover string we attempted to parse is unknown."),
  36. ProtoverError::ExceedsNameLimit
  37. => write!(f, "An unrecognised protocol name was too long."),
  38. ProtoverError::InvalidProtocol
  39. => write!(f, "A protocol name includes invalid characters."),
  40. }
  41. }
  42. }