lib

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

error.rs (3531B)


      1 //! Normalized Nostr Connect errors.
      2 
      3 use thiserror::Error;
      4 
      5 #[derive(Debug, Error, Clone, PartialEq, Eq)]
      6 pub enum RadrootsNostrConnectError {
      7     #[error("NIP-46 request encryption failed: {reason}")]
      8     Encrypt { reason: String },
      9     #[error("NIP-46 response decryption failed: {reason}")]
     10     Decrypt { reason: String },
     11     #[error("NIP-46 event signing failed: {reason}")]
     12     Sign { reason: String },
     13     #[error("NIP-46 transport failed: {reason}")]
     14     Transport { reason: String },
     15     #[error("NIP-46 request timed out")]
     16     RequestTimedOut,
     17     #[error("invalid NIP-46 client key")]
     18     InvalidClientKey,
     19     #[error("invalid NIP-46 client target: {reason}")]
     20     InvalidClientTarget { reason: &'static str },
     21     #[error("invalid NIP-46 client event")]
     22     InvalidClientEvent,
     23     #[error("invalid NIP-46 client state: {reason}")]
     24     InvalidClientState { reason: &'static str },
     25     #[error("invalid NIP-46 server request: {reason}")]
     26     InvalidServerRequest { reason: &'static str },
     27     #[error("invalid NIP-46 server state: {reason}")]
     28     InvalidServerState { reason: &'static str },
     29     #[error("unsupported NIP-46 method `{0}`")]
     30     UnsupportedMethod(crate::method::Method),
     31     #[error("replayed NIP-46 request")]
     32     ReplayedRequest,
     33     #[error("invalid NIP-46 request id: {reason}")]
     34     InvalidRequestId { reason: &'static str },
     35     #[error("NIP-46 response id does not match the request")]
     36     WrongRequestId,
     37     #[error("NIP-46 response signer does not match the expected signer")]
     38     WrongResponseSigner,
     39     #[error("replayed NIP-46 response")]
     40     ReplayedResponse,
     41     #[error("invalid NIP-46 response envelope: {reason}")]
     42     InvalidResponseEnvelope { reason: &'static str },
     43     #[error("invalid NIP-46 method `{0}`")]
     44     InvalidMethod(String),
     45     #[error("invalid NIP-46 permission `{0}`")]
     46     InvalidPermission(String),
     47     #[error("invalid public key `{value}`: {reason}")]
     48     InvalidPublicKey { value: String, reason: String },
     49     #[error("invalid relay url `{value}`: {reason}")]
     50     InvalidRelayUrl { value: String, reason: String },
     51     #[error("invalid url `{value}`: {reason}")]
     52     InvalidUrl { value: String, reason: String },
     53     #[error("invalid NIP-46 client metadata field `{field}`: {reason}")]
     54     InvalidClientMetadata { field: &'static str, reason: String },
     55     #[error("NIP-46 client metadata exceeds {max} bytes (received {received})")]
     56     ClientMetadataTooLarge { max: usize, received: usize },
     57     #[error("invalid URI scheme `{0}`")]
     58     InvalidUriScheme(String),
     59     #[error("invalid NIP-46 uri")]
     60     InvalidUri,
     61     #[error("missing public key in URI authority")]
     62     MissingPublicKey,
     63     #[error("missing relay in URI")]
     64     MissingRelay,
     65     #[error("missing secret in nostrconnect uri")]
     66     MissingSecret,
     67     #[error("missing response result")]
     68     MissingResult,
     69     #[error("invalid parameter count for method `{method}`: expected {expected}, got {received}")]
     70     InvalidParams {
     71         method: String,
     72         expected: &'static str,
     73         received: usize,
     74     },
     75     #[error("invalid request payload for method `{method}`: {reason}")]
     76     InvalidRequestPayload { method: String, reason: String },
     77     #[error("invalid response payload for method `{method}`: {reason}")]
     78     InvalidResponsePayload { method: String, reason: String },
     79     #[error("JSON error: {0}")]
     80     Json(String),
     81 }
     82 
     83 impl From<serde_json::Error> for RadrootsNostrConnectError {
     84     fn from(value: serde_json::Error) -> Self {
     85         Self::Json(value.to_string())
     86     }
     87 }