error.rs (1138B)
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("io error: {0}")] 33 Io(#[from] std::io::Error), 34 35 #[error("nostrdb error: {0}")] 36 Nostrdb(#[from] nostrdb::Error), 37 38 #[error("{0}")] 39 Generic(String), 40 } 41 42 impl From<String> for Error { 43 fn from(s: String) -> Self { 44 Error::Generic(s) 45 } 46 } 47 48 impl From<TryFromSliceError> for Error { 49 fn from(_e: TryFromSliceError) -> Self { 50 Error::InvalidByteSize 51 } 52 } 53 54 impl From<hex::FromHexError> for Error { 55 fn from(_e: hex::FromHexError) -> Self { 56 Error::HexDecodeFailed 57 } 58 }