use thiserror::Error;
#[derive(Debug, Error)]
pub enum FederationError {
#[error("connection to peer failed: {0}")]
ConnectionFailed(String),
#[error("federation handshake failed: {0}")]
HandshakeFailed(String),
#[error("namespace conflict: {pattern} claimed by both {a} and {b}")]
NamespaceConflict {
pattern: String,
a: String,
b: String,
},
#[error("peer not found: {0}")]
PeerNotFound(String),
#[error("transport error: {0}")]
Transport(String),
#[error("codec error: {0}")]
Codec(String),
#[error("sync error: {0}")]
Sync(String),
#[error("already connected to peer: {0}")]
AlreadyConnected(String),
#[error("configuration error: {0}")]
Config(String),
}
pub type Result<T> = std::result::Result<T, FederationError>;
impl From<clasp_core::Error> for FederationError {
fn from(e: clasp_core::Error) -> Self {
FederationError::Codec(e.to_string())
}
}
impl From<clasp_transport::TransportError> for FederationError {
fn from(e: clasp_transport::TransportError) -> Self {
FederationError::Transport(e.to_string())
}
}