Skip to main content

clasp_federation/
error.rs

1//! Federation error types
2
3use thiserror::Error;
4
5/// Federation-specific errors
6#[derive(Debug, Error)]
7pub enum FederationError {
8    /// Peer connection failed
9    #[error("connection to peer failed: {0}")]
10    ConnectionFailed(String),
11
12    /// Handshake failed (peer did not announce federation feature)
13    #[error("federation handshake failed: {0}")]
14    HandshakeFailed(String),
15
16    /// Namespace conflict (two peers claim the same namespace)
17    #[error("namespace conflict: {pattern} claimed by both {a} and {b}")]
18    NamespaceConflict {
19        pattern: String,
20        a: String,
21        b: String,
22    },
23
24    /// Peer not found
25    #[error("peer not found: {0}")]
26    PeerNotFound(String),
27
28    /// Transport error
29    #[error("transport error: {0}")]
30    Transport(String),
31
32    /// Codec error
33    #[error("codec error: {0}")]
34    Codec(String),
35
36    /// Sync error
37    #[error("sync error: {0}")]
38    Sync(String),
39
40    /// Already connected to this peer
41    #[error("already connected to peer: {0}")]
42    AlreadyConnected(String),
43
44    /// Configuration error
45    #[error("configuration error: {0}")]
46    Config(String),
47}
48
49/// Result type for federation operations
50pub type Result<T> = std::result::Result<T, FederationError>;
51
52impl From<clasp_core::Error> for FederationError {
53    fn from(e: clasp_core::Error) -> Self {
54        FederationError::Codec(e.to_string())
55    }
56}
57
58impl From<clasp_transport::TransportError> for FederationError {
59    fn from(e: clasp_transport::TransportError) -> Self {
60        FederationError::Transport(e.to_string())
61    }
62}