1use thiserror::Error;
17
18#[derive(Error, Debug)]
24pub enum AegisError {
25 #[error("storage error: {0}")]
27 Storage(String),
28
29 #[error("block not found: {0}")]
30 BlockNotFound(u64),
31
32 #[error("page not found: {0}")]
33 PageNotFound(u64),
34
35 #[error("corruption detected: {0}")]
36 Corruption(String),
37
38 #[error("transaction error: {0}")]
40 Transaction(String),
41
42 #[error("transaction aborted: {0}")]
43 TransactionAborted(String),
44
45 #[error("deadlock detected")]
46 Deadlock,
47
48 #[error("lock timeout")]
49 LockTimeout,
50
51 #[error("serialization failure")]
52 SerializationFailure,
53
54 #[error("parse error: {0}")]
56 Parse(String),
57
58 #[error("type error: {0}")]
59 TypeError(String),
60
61 #[error("execution error: {0}")]
62 Execution(String),
63
64 #[error("table not found: {0}")]
65 TableNotFound(String),
66
67 #[error("column not found: {0}")]
68 ColumnNotFound(String),
69
70 #[error("index not found: {0}")]
71 IndexNotFound(String),
72
73 #[error("constraint violation: {0}")]
75 ConstraintViolation(String),
76
77 #[error("unique constraint violation: {0}")]
78 UniqueViolation(String),
79
80 #[error("foreign key violation: {0}")]
81 ForeignKeyViolation(String),
82
83 #[error("check constraint violation: {0}")]
84 CheckViolation(String),
85
86 #[error("replication error: {0}")]
88 Replication(String),
89
90 #[error("node not found: {0}")]
91 NodeNotFound(String),
92
93 #[error("quorum not reached")]
94 QuorumNotReached,
95
96 #[error("leader not elected")]
97 LeaderNotElected,
98
99 #[error("authentication failed: {0}")]
101 AuthenticationFailed(String),
102
103 #[error("authorization denied: {0}")]
104 AuthorizationDenied(String),
105
106 #[error("IO error: {0}")]
108 Io(#[from] std::io::Error),
109
110 #[error("serialization error: {0}")]
112 Serialization(String),
113
114 #[error("encryption error: {0}")]
116 Encryption(String),
117
118 #[error("configuration error: {0}")]
120 Configuration(String),
121
122 #[error("internal error: {0}")]
124 Internal(String),
125
126 #[error("resource exhausted: {0}")]
128 ResourceExhausted(String),
129
130 #[error("memory limit exceeded")]
131 MemoryLimitExceeded,
132
133 #[error("network error: {0}")]
135 Network(String),
136
137 #[error("connection refused: {0}")]
138 ConnectionRefused(String),
139
140 #[error("timeout: {0}")]
141 Timeout(String),
142
143 #[error("vault error: {0}")]
145 Vault(String),
146
147 #[error("shield error: {0}")]
149 Shield(String),
150}
151
152pub type Result<T> = std::result::Result<T, AegisError>;
158
159impl AegisError {
164 pub fn is_retryable(&self) -> bool {
166 matches!(
167 self,
168 AegisError::Deadlock
169 | AegisError::LockTimeout
170 | AegisError::SerializationFailure
171 | AegisError::QuorumNotReached
172 | AegisError::LeaderNotElected
173 | AegisError::Network(_)
174 | AegisError::Timeout(_)
175 | AegisError::TransactionAborted(_)
176 | AegisError::Replication(_)
177 | AegisError::NodeNotFound(_)
178 | AegisError::ConnectionRefused(_)
179 | AegisError::ResourceExhausted(_)
180 | AegisError::MemoryLimitExceeded
181 | AegisError::Io(_)
182 )
183 }
184
185 pub fn is_user_error(&self) -> bool {
187 matches!(
188 self,
189 AegisError::Parse(_)
190 | AegisError::TypeError(_)
191 | AegisError::TableNotFound(_)
192 | AegisError::ColumnNotFound(_)
193 | AegisError::ConstraintViolation(_)
194 | AegisError::UniqueViolation(_)
195 | AegisError::ForeignKeyViolation(_)
196 | AegisError::CheckViolation(_)
197 | AegisError::AuthenticationFailed(_)
198 | AegisError::AuthorizationDenied(_)
199 | AegisError::Execution(_)
200 | AegisError::IndexNotFound(_)
201 | AegisError::BlockNotFound(_)
202 | AegisError::PageNotFound(_)
203 | AegisError::Configuration(_)
204 )
205 }
206
207 pub fn is_system_error(&self) -> bool {
209 matches!(
210 self,
211 AegisError::Storage(_)
212 | AegisError::Corruption(_)
213 | AegisError::Internal(_)
214 | AegisError::Encryption(_)
215 | AegisError::Serialization(_)
216 )
217 }
218
219 pub fn is_constraint_error(&self) -> bool {
221 matches!(
222 self,
223 AegisError::ConstraintViolation(_)
224 | AegisError::UniqueViolation(_)
225 | AegisError::ForeignKeyViolation(_)
226 | AegisError::CheckViolation(_)
227 )
228 }
229}