lib

Core libraries for Radroots
git clone https://radroots.dev/git/lib.git
Log | Files | Refs | README | LICENSE

error.rs (1412B)


      1 use core::fmt;
      2 
      3 #[derive(Debug)]
      4 pub enum JobParseError {
      5     MissingTag(&'static str),
      6     InvalidTag(&'static str),
      7     InvalidNumber(&'static str, core::num::ParseIntError),
      8     NonWholeSats(&'static str),
      9     AmountOverflow(&'static str),
     10     MissingChainTag(&'static str),
     11 }
     12 
     13 impl fmt::Display for JobParseError {
     14     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
     15         match self {
     16             JobParseError::MissingTag(t) => write!(f, "missing tag: {}", t),
     17             JobParseError::InvalidTag(t) => write!(f, "invalid tag structure for '{}'", t),
     18             JobParseError::InvalidNumber(t, e) => write!(f, "invalid number in '{}': {}", t, e),
     19             JobParseError::NonWholeSats(t) => {
     20                 write!(
     21                     f,
     22                     "amount in msats is not a whole number of sats for '{}'",
     23                     t
     24                 )
     25             }
     26             JobParseError::AmountOverflow(t) => {
     27                 write!(f, "amount overflow in '{}' (does not fit u32 sat)", t)
     28             }
     29             JobParseError::MissingChainTag(t) => write!(f, "missing required chain tag: {}", t),
     30         }
     31     }
     32 }
     33 
     34 #[cfg(feature = "std")]
     35 impl std::error::Error for JobParseError {
     36     fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
     37         match self {
     38             JobParseError::InvalidNumber(_, e) => Some(e),
     39             _ => None,
     40         }
     41     }
     42 }