lib

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

error.rs (1847B)


      1 use alloc::string::String;
      2 use core::fmt;
      3 use radroots_simplex_agent_proto::prelude::RadrootsSimplexAgentProtoError;
      4 use radroots_simplex_agent_store::prelude::RadrootsSimplexAgentStoreError;
      5 use radroots_simplex_smp_crypto::prelude::RadrootsSimplexSmpCryptoError;
      6 
      7 #[derive(Debug, Clone, PartialEq, Eq)]
      8 pub enum RadrootsSimplexAgentRuntimeError {
      9     Proto(RadrootsSimplexAgentProtoError),
     10     Store(RadrootsSimplexAgentStoreError),
     11     Crypto(RadrootsSimplexSmpCryptoError),
     12     MissingConfig(&'static str),
     13     InvalidConfig(&'static str),
     14     Runtime(String),
     15 }
     16 
     17 impl From<RadrootsSimplexAgentProtoError> for RadrootsSimplexAgentRuntimeError {
     18     fn from(value: RadrootsSimplexAgentProtoError) -> Self {
     19         Self::Proto(value)
     20     }
     21 }
     22 
     23 impl From<RadrootsSimplexAgentStoreError> for RadrootsSimplexAgentRuntimeError {
     24     fn from(value: RadrootsSimplexAgentStoreError) -> Self {
     25         Self::Store(value)
     26     }
     27 }
     28 
     29 impl From<RadrootsSimplexSmpCryptoError> for RadrootsSimplexAgentRuntimeError {
     30     fn from(value: RadrootsSimplexSmpCryptoError) -> Self {
     31         Self::Crypto(value)
     32     }
     33 }
     34 
     35 impl fmt::Display for RadrootsSimplexAgentRuntimeError {
     36     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
     37         match self {
     38             Self::Proto(error) => write!(f, "{error}"),
     39             Self::Store(error) => write!(f, "{error}"),
     40             Self::Crypto(error) => write!(f, "{error}"),
     41             Self::MissingConfig(field) => {
     42                 write!(f, "missing SimpleX agent runtime config `{field}`")
     43             }
     44             Self::InvalidConfig(field) => {
     45                 write!(f, "invalid SimpleX agent runtime config `{field}`")
     46             }
     47             Self::Runtime(message) => write!(f, "{message}"),
     48         }
     49     }
     50 }
     51 
     52 #[cfg(feature = "std")]
     53 impl std::error::Error for RadrootsSimplexAgentRuntimeError {}