app

Local-first trade for farms and co-ops
git clone https://radroots.dev/git/app.git
Log | Files | Refs | README | LICENSE

error.rs (2496B)


      1 use radroots_nostr_connect::prelude::{RadrootsNostrConnectError, RadrootsNostrConnectMethod};
      2 use std::fmt;
      3 
      4 #[derive(Debug, Clone, PartialEq, Eq)]
      5 pub enum RadrootsAppRemoteSignerError {
      6     EmptyInput,
      7     UnsupportedClientUri,
      8     MissingDiscoveryUri,
      9     InvalidDiscoveryUrl(String),
     10     InvalidBunkerUri(String),
     11     InvalidSessionStore(String),
     12     SessionStoreIo(String),
     13     PendingSessionExists,
     14     MissingClientSecret,
     15     ConnectFailed(String),
     16     RequestTimedOut {
     17         method: RadrootsNostrConnectMethod,
     18     },
     19     UnexpectedResponse {
     20         method: RadrootsNostrConnectMethod,
     21         response: String,
     22     },
     23 }
     24 
     25 impl fmt::Display for RadrootsAppRemoteSignerError {
     26     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
     27         match self {
     28             Self::EmptyInput => f.write_str("enter a bunker or discovery url to continue"),
     29             Self::UnsupportedClientUri => f.write_str(
     30                 "enter a bunker or discovery url from the signer; raw nostrconnect client uris are signer-side only",
     31             ),
     32             Self::MissingDiscoveryUri => {
     33                 f.write_str("discovery url does not contain a remote signer uri")
     34             }
     35             Self::InvalidDiscoveryUrl(reason) => write!(f, "invalid discovery url: {reason}"),
     36             Self::InvalidBunkerUri(reason) => write!(f, "invalid remote signer uri: {reason}"),
     37             Self::InvalidSessionStore(reason) => write!(f, "invalid remote signer store: {reason}"),
     38             Self::SessionStoreIo(reason) => write!(f, "remote signer storage failed: {reason}"),
     39             Self::PendingSessionExists => {
     40                 f.write_str("a remote signer connection is already pending approval")
     41             }
     42             Self::MissingClientSecret => f.write_str("remote signer session secret is missing"),
     43             Self::ConnectFailed(reason) => write!(f, "remote signer connection failed: {reason}"),
     44             Self::RequestTimedOut { method } => {
     45                 write!(f, "remote signer request `{method}` timed out")
     46             }
     47             Self::UnexpectedResponse { method, response } => {
     48                 write!(f, "remote signer returned an unexpected `{method}` response: {response}")
     49             }
     50         }
     51     }
     52 }
     53 
     54 impl std::error::Error for RadrootsAppRemoteSignerError {}
     55 
     56 impl From<RadrootsNostrConnectError> for RadrootsAppRemoteSignerError {
     57     fn from(value: RadrootsNostrConnectError) -> Self {
     58         Self::InvalidBunkerUri(value.to_string())
     59     }
     60 }