Skip to main content

oxirs_cluster/
error.rs

1//! Error types for the OxiRS cluster module
2
3use thiserror::Error;
4
5/// Result type for cluster operations
6pub type Result<T> = std::result::Result<T, ClusterError>;
7
8/// Errors that can occur in the cluster module
9#[derive(Debug, Error)]
10pub enum ClusterError {
11    /// Configuration error
12    #[error("Configuration error: {0}")]
13    Config(String),
14
15    /// Network communication error
16    #[error("Network error: {0}")]
17    Network(String),
18
19    /// Storage backend error
20    #[error("Storage error: {0}")]
21    Storage(String),
22
23    /// Consensus error
24    #[error("Consensus error: {0}")]
25    Consensus(String),
26
27    /// Not the leader node
28    #[error("Not the leader node")]
29    NotLeader,
30
31    /// Lock acquisition error
32    #[error("Lock error: {0}")]
33    Lock(String),
34
35    /// Serialization error
36    #[error("Serialization error: {0}")]
37    Serialize(String),
38
39    /// Parse error
40    #[error("Parse error: {0}")]
41    Parse(String),
42
43    /// Runtime error
44    #[error("Runtime error: {0}")]
45    Runtime(String),
46
47    /// Byzantine fault detected
48    #[error("Byzantine fault detected: {0}")]
49    Byzantine(String),
50
51    /// Shard not found
52    #[error("Shard not found: {0}")]
53    ShardNotFound(crate::shard::ShardId),
54
55    /// Circuit breaker is open
56    #[error("Circuit breaker is open - too many failures")]
57    CircuitOpen,
58
59    /// Compression error
60    #[error("Compression error: {0}")]
61    Compression(String),
62
63    /// Encryption error
64    #[error("Encryption error: {0}")]
65    Encryption(String),
66
67    /// Invalid tenant error
68    #[error("Invalid tenant: {0}")]
69    InvalidTenant(String),
70
71    /// Resource limit exceeded
72    #[error("Resource limit exceeded: {0}")]
73    ResourceLimit(String),
74
75    /// Generic error
76    #[error("{0}")]
77    Other(String),
78}
79
80impl From<std::io::Error> for ClusterError {
81    fn from(err: std::io::Error) -> Self {
82        ClusterError::Network(err.to_string())
83    }
84}
85
86impl From<serde_json::Error> for ClusterError {
87    fn from(err: serde_json::Error) -> Self {
88        ClusterError::Serialize(err.to_string())
89    }
90}
91
92impl From<anyhow::Error> for ClusterError {
93    fn from(err: anyhow::Error) -> Self {
94        ClusterError::Other(err.to_string())
95    }
96}