errors.rs 1.8 KB

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