error.rs (1075B)
1 //use nostr::prelude::secp256k1; 2 use std::array::TryFromSliceError; 3 use thiserror::Error; 4 5 #[derive(Error, Debug)] 6 pub enum Error { 7 #[error("message is empty")] 8 Empty, 9 10 #[error("decoding failed")] 11 DecodeFailed, 12 13 #[error("hex decoding failed")] 14 HexDecodeFailed, 15 16 #[error("invalid bech32")] 17 InvalidBech32, 18 19 #[error("invalid byte size")] 20 InvalidByteSize, 21 22 #[error("invalid signature")] 23 InvalidSignature, 24 25 #[error("invalid public key")] 26 InvalidPublicKey, 27 28 // Secp(secp256k1::Error), 29 #[error("json error: {0}")] 30 Json(#[from] serde_json::Error), 31 32 #[error("nostrdb error: {0}")] 33 Nostrdb(#[from] nostrdb::Error), 34 35 #[error("{0}")] 36 Generic(String), 37 } 38 39 impl From<String> for Error { 40 fn from(s: String) -> Self { 41 Error::Generic(s) 42 } 43 } 44 45 impl From<TryFromSliceError> for Error { 46 fn from(_e: TryFromSliceError) -> Self { 47 Error::InvalidByteSize 48 } 49 } 50 51 impl From<hex::FromHexError> for Error { 52 fn from(_e: hex::FromHexError) -> Self { 53 Error::HexDecodeFailed 54 } 55 }