notedeck

One damus client to rule them all
git clone git://jb55.com/notedeck
Log | Files | Refs | README | LICENSE

error.rs (1868B)


      1 //use nostr::prelude::secp256k1;
      2 use std::array::TryFromSliceError;
      3 use std::fmt;
      4 
      5 #[derive(Debug)]
      6 pub enum Error {
      7     Empty,
      8     DecodeFailed,
      9     HexDecodeFailed,
     10     InvalidBech32,
     11     InvalidByteSize,
     12     InvalidSignature,
     13     InvalidPublicKey,
     14     // Secp(secp256k1::Error),
     15     Json(serde_json::Error),
     16     Nostrdb(nostrdb::Error),
     17     Generic(String),
     18 }
     19 
     20 impl fmt::Display for Error {
     21     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
     22         match self {
     23             Self::Empty => write!(f, "message is empty"),
     24             Self::DecodeFailed => write!(f, "decoding failed"),
     25             Self::InvalidSignature => write!(f, "invalid signature"),
     26             Self::HexDecodeFailed => write!(f, "hex decoding failed"),
     27             Self::InvalidByteSize => write!(f, "invalid byte size"),
     28             Self::InvalidBech32 => write!(f, "invalid bech32 string"),
     29             Self::InvalidPublicKey => write!(f, "invalid public key"),
     30             //Self::Secp(e) => write!(f, "{e}"),
     31             Self::Json(e) => write!(f, "{e}"),
     32             Self::Nostrdb(e) => write!(f, "{e}"),
     33             Self::Generic(e) => write!(f, "{e}"),
     34         }
     35     }
     36 }
     37 
     38 impl From<String> for Error {
     39     fn from(s: String) -> Self {
     40         Error::Generic(s)
     41     }
     42 }
     43 
     44 impl From<TryFromSliceError> for Error {
     45     fn from(_e: TryFromSliceError) -> Self {
     46         Error::InvalidByteSize
     47     }
     48 }
     49 
     50 impl From<hex::FromHexError> for Error {
     51     fn from(_e: hex::FromHexError) -> Self {
     52         Error::HexDecodeFailed
     53     }
     54 }
     55 
     56 /*
     57 impl From<secp256k1::Error> for Error {
     58     fn from(e: secp256k1::Error) -> Self {
     59         Error::Secp(e)
     60     }
     61 }
     62 */
     63 
     64 impl From<serde_json::Error> for Error {
     65     fn from(e: serde_json::Error) -> Self {
     66         Error::Json(e)
     67     }
     68 }
     69 
     70 impl From<nostrdb::Error> for Error {
     71     fn from(e: nostrdb::Error) -> Self {
     72         Error::Nostrdb(e)
     73     }
     74 }