error.rs (1207B)
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: {0}")] 11 DecodeFailed(String), 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 #[error("invalid relay url")] 29 InvalidRelayUrl, 30 31 // Secp(secp256k1::Error), 32 #[error("json error: {0}")] 33 Json(#[from] serde_json::Error), 34 35 #[error("io error: {0}")] 36 Io(#[from] std::io::Error), 37 38 #[error("nostrdb error: {0}")] 39 Nostrdb(#[from] nostrdb::Error), 40 41 #[error("{0}")] 42 Generic(String), 43 } 44 45 impl From<String> for Error { 46 fn from(s: String) -> Self { 47 Error::Generic(s) 48 } 49 } 50 51 impl From<TryFromSliceError> for Error { 52 fn from(_e: TryFromSliceError) -> Self { 53 Error::InvalidByteSize 54 } 55 } 56 57 impl From<hex::FromHexError> for Error { 58 fn from(_e: hex::FromHexError) -> Self { 59 Error::HexDecodeFailed 60 } 61 }