use thiserror::Error;
pub type Result<T> = std::result::Result<T, ClusterError>;
#[derive(Debug, Error)]
pub enum ClusterError {
#[error("Configuration error: {0}")]
Config(String),
#[error("Network error: {0}")]
Network(String),
#[error("Storage error: {0}")]
Storage(String),
#[error("Consensus error: {0}")]
Consensus(String),
#[error("Not the leader node")]
NotLeader,
#[error("Lock error: {0}")]
Lock(String),
#[error("Serialization error: {0}")]
Serialize(String),
#[error("Parse error: {0}")]
Parse(String),
#[error("Runtime error: {0}")]
Runtime(String),
#[error("Byzantine fault detected: {0}")]
Byzantine(String),
#[error("Shard not found: {0}")]
ShardNotFound(crate::shard::ShardId),
#[error("Circuit breaker is open - too many failures")]
CircuitOpen,
#[error("Compression error: {0}")]
Compression(String),
#[error("Encryption error: {0}")]
Encryption(String),
#[error("Invalid tenant: {0}")]
InvalidTenant(String),
#[error("Resource limit exceeded: {0}")]
ResourceLimit(String),
#[error("{0}")]
Other(String),
}
impl From<std::io::Error> for ClusterError {
fn from(err: std::io::Error) -> Self {
ClusterError::Network(err.to_string())
}
}
impl From<serde_json::Error> for ClusterError {
fn from(err: serde_json::Error) -> Self {
ClusterError::Serialize(err.to_string())
}
}
impl From<anyhow::Error> for ClusterError {
fn from(err: anyhow::Error) -> Self {
ClusterError::Other(err.to_string())
}
}