lib

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

error.rs (1988B)


      1 use thiserror::Error;
      2 
      3 #[derive(Debug, Error)]
      4 pub enum RadrootsNostrRuntimeError {
      5     #[error("runtime not started")]
      6     RuntimeNotStarted,
      7 
      8     #[error("runtime already started")]
      9     RuntimeAlreadyStarted,
     10 
     11     #[error("runtime shutdown")]
     12     RuntimeShutdown,
     13 
     14     #[error("missing required runtime configuration: {0}")]
     15     MissingConfig(&'static str),
     16 
     17     #[error("invalid runtime configuration: {0}")]
     18     InvalidConfig(&'static str),
     19 
     20     #[error("nostr client error: {0}")]
     21     Client(String),
     22 
     23     #[error("subscription not found: {0}")]
     24     SubscriptionNotFound(String),
     25 
     26     #[error("runtime error: {0}")]
     27     Runtime(String),
     28 }
     29 
     30 #[cfg(test)]
     31 mod tests {
     32     use super::*;
     33 
     34     #[test]
     35     fn error_variants_render_messages() {
     36         assert_eq!(
     37             RadrootsNostrRuntimeError::RuntimeNotStarted.to_string(),
     38             "runtime not started"
     39         );
     40         assert_eq!(
     41             RadrootsNostrRuntimeError::RuntimeAlreadyStarted.to_string(),
     42             "runtime already started"
     43         );
     44         assert_eq!(
     45             RadrootsNostrRuntimeError::RuntimeShutdown.to_string(),
     46             "runtime shutdown"
     47         );
     48         assert_eq!(
     49             RadrootsNostrRuntimeError::MissingConfig("keys").to_string(),
     50             "missing required runtime configuration: keys"
     51         );
     52         assert_eq!(
     53             RadrootsNostrRuntimeError::InvalidConfig("queue_capacity").to_string(),
     54             "invalid runtime configuration: queue_capacity"
     55         );
     56         assert_eq!(
     57             RadrootsNostrRuntimeError::Client("client failure".into()).to_string(),
     58             "nostr client error: client failure"
     59         );
     60         assert_eq!(
     61             RadrootsNostrRuntimeError::SubscriptionNotFound("sub-1".into()).to_string(),
     62             "subscription not found: sub-1"
     63         );
     64         assert_eq!(
     65             RadrootsNostrRuntimeError::Runtime("runtime failure".into()).to_string(),
     66             "runtime error: runtime failure"
     67         );
     68     }
     69 }