Skip to main content

tenzro_network/
error.rs

1//! Network error types for Tenzro Network
2
3use thiserror::Error;
4
5/// Network-specific errors
6#[derive(Error, Debug)]
7pub enum NetworkError {
8    /// I/O error
9    #[error("I/O error: {0}")]
10    Io(#[from] std::io::Error),
11
12    /// libp2p transport error
13    #[error("Transport error: {0}")]
14    Transport(String),
15
16    /// Connection error
17    #[error("Connection error: {0}")]
18    Connection(String),
19
20    /// Peer not found
21    #[error("Peer not found: {0}")]
22    PeerNotFound(String),
23
24    /// Invalid message
25    #[error("Invalid message: {0}")]
26    InvalidMessage(String),
27
28    /// Serialization error
29    #[error("Serialization error: {0}")]
30    Serialization(#[from] bincode::Error),
31
32    /// Gossipsub publish error
33    #[error("Failed to publish to topic: {0}")]
34    PublishError(String),
35
36    /// Subscription error
37    #[error("Subscription error: {0}")]
38    SubscriptionError(String),
39
40    /// DHT error
41    #[error("DHT error: {0}")]
42    DhtError(String),
43
44    /// Peer banned
45    #[error("Peer is banned: {0}")]
46    PeerBanned(String),
47
48    /// Maximum peers reached
49    #[error("Maximum peers reached")]
50    MaxPeersReached,
51
52    /// Invalid configuration
53    #[error("Invalid configuration: {0}")]
54    InvalidConfig(String),
55
56    /// Channel send error
57    #[error("Channel send error")]
58    ChannelSend,
59
60    /// Channel receive error
61    #[error("Channel receive error")]
62    ChannelReceive,
63
64    /// Service not started
65    #[error("Service not started")]
66    ServiceNotStarted,
67
68    /// Service already running
69    #[error("Service already running")]
70    ServiceAlreadyRunning,
71
72    /// Timeout error
73    #[error("Operation timed out")]
74    Timeout,
75
76    /// Protocol not supported
77    #[error("Protocol not supported: {0}")]
78    ProtocolNotSupported(String),
79}
80
81/// Result type for network operations
82pub type Result<T> = std::result::Result<T, NetworkError>;