1use thiserror::Error;
4
5pub type Result<T> = std::result::Result<T, ClusterError>;
7
8#[derive(Debug, Error)]
10pub enum ClusterError {
11 #[error("Configuration error: {0}")]
13 Config(String),
14
15 #[error("Network error: {0}")]
17 Network(String),
18
19 #[error("Storage error: {0}")]
21 Storage(String),
22
23 #[error("Consensus error: {0}")]
25 Consensus(String),
26
27 #[error("Not the leader node")]
29 NotLeader,
30
31 #[error("Lock error: {0}")]
33 Lock(String),
34
35 #[error("Serialization error: {0}")]
37 Serialize(String),
38
39 #[error("Parse error: {0}")]
41 Parse(String),
42
43 #[error("Runtime error: {0}")]
45 Runtime(String),
46
47 #[error("Byzantine fault detected: {0}")]
49 Byzantine(String),
50
51 #[error("Shard not found: {0}")]
53 ShardNotFound(crate::shard::ShardId),
54
55 #[error("Circuit breaker is open - too many failures")]
57 CircuitOpen,
58
59 #[error("Compression error: {0}")]
61 Compression(String),
62
63 #[error("Encryption error: {0}")]
65 Encryption(String),
66
67 #[error("Invalid tenant: {0}")]
69 InvalidTenant(String),
70
71 #[error("Resource limit exceeded: {0}")]
73 ResourceLimit(String),
74
75 #[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}