Skip to main content

shadow_core/
error.rs

1use thiserror::Error;
2
3/// Main error type for the Shadow Network
4#[derive(Error, Debug)]
5pub enum ShadowError {
6    #[error("Transport error: {0}")]
7    Transport(String),
8
9    #[error("Steganography error: {0}")]
10    Steganography(String),
11
12    #[error("Cryptographic error: {0}")]
13    Crypto(String),
14
15    #[error("DHT error: {0}")]
16    Dht(String),
17
18    #[error("NAT traversal error: {0}")]
19    NatTraversal(String),
20
21    #[error("Storage error: {0}")]
22    Storage(String),
23
24    #[error("Peer not found: {0}")]
25    PeerNotFound(String),
26
27    #[error("Invalid packet: {0}")]
28    InvalidPacket(String),
29
30    #[error("Network error: {0}")]
31    Network(String),
32
33    #[error("Configuration error: {0}")]
34    Configuration(String),
35
36    #[error("IO error: {0}")]
37    Io(#[from] std::io::Error),
38
39    #[error("Serialization error: {0}")]
40    Serialization(String),
41
42    #[error("Timeout")]
43    Timeout,
44
45    #[error("Not implemented: {0}")]
46    NotImplemented(String),
47
48    #[error("Internal error: {0}")]
49    Internal(String),
50}
51
52/// Convenience Result type with ShadowError
53pub type Result<T> = std::result::Result<T, ShadowError>;
54
55impl From<bincode::Error> for ShadowError {
56    fn from(err: bincode::Error) -> Self {
57        ShadowError::Serialization(err.to_string())
58    }
59}
60
61impl From<serde_json::Error> for ShadowError {
62    fn from(err: serde_json::Error) -> Self {
63        ShadowError::Serialization(err.to_string())
64    }
65}