errors.rs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 => write!(
  25. f,
  26. "Two or more (low, high) protover ranges would overlap once expanded."
  27. ),
  28. ProtoverError::LowGreaterThanHigh => write!(
  29. f,
  30. "The low in a (low, high) protover range was greater than high."
  31. ),
  32. ProtoverError::Unparseable => write!(f, "The protover string was unparseable."),
  33. ProtoverError::ExceedsMax => write!(
  34. f,
  35. "The high in a (low, high) protover range exceeds u32::MAX."
  36. ),
  37. ProtoverError::ExceedsExpansionLimit => write!(
  38. f,
  39. "The protover string would exceed the maximum expansion limit."
  40. ),
  41. ProtoverError::UnknownProtocol => write!(
  42. f,
  43. "A protocol in the protover string we attempted to parse is unknown."
  44. ),
  45. ProtoverError::ExceedsNameLimit => {
  46. write!(f, "An unrecognised protocol name was too long.")
  47. }
  48. ProtoverError::InvalidProtocol => {
  49. write!(f, "A protocol name includes invalid characters.")
  50. }
  51. }
  52. }
  53. }