1use thiserror::Error;
7
8#[derive(Debug, Clone, Error)]
10pub enum Error {
11 #[error("System initialization failed: {0}")]
16 SystemInit(String),
17
18 #[error("Failed to initialize {actor}: {reason}")]
20 ActorCreation { actor: String, reason: String },
21
22 #[error("Required resource '{name}' not found: {reason}")]
24 MissingResource { name: String, reason: String },
25
26 #[error("Network error: {0}")]
31 Network(String),
32
33 #[error("Unable to retrieve network state: {0}")]
35 NetworkState(String),
36
37 #[error("Request processing failed: {0}")]
42 RequestProcessing(String),
43
44 #[error("Invalid request signature: {0}")]
46 InvalidSignature(String),
47
48 #[error("Failed to sign request: {0}")]
50 SigningFailed(String),
51
52 #[error("Request '{0}' not found")]
54 RequestNotFound(String),
55
56 #[error("Request is in invalid state: {0}")]
58 InvalidRequestState(String),
59
60 #[error("Invalid approval state: cannot set approval to '{0}'")]
65 InvalidApprovalState(String),
66
67 #[error("No approval request found for subject '{0}'")]
69 ApprovalNotFound(String),
70
71 #[error("Failed to update approval state: {0}")]
73 ApprovalUpdateFailed(String),
74
75 #[error("Subject '{0}' not found")]
80 SubjectNotFound(String),
81
82 #[error("Subject '{0}' is not active")]
84 SubjectNotActive(String),
85
86 #[error("Governance '{0}' not found")]
88 GovernanceNotFound(String),
89
90 #[error("Governance '{governance_id}' still has trackers associated")]
92 GovernanceHasTrackers {
93 governance_id: String,
94 trackers: Vec<String>,
95 },
96
97 #[error("Invalid subject identifier: {0}")]
99 InvalidSubjectId(String),
100
101 #[error("Authorization failed: {0}")]
106 Unauthorized(String),
107
108 #[error("Insufficient permissions: {0}")]
110 Forbidden(String),
111
112 #[error("Safe mode: {0}")]
114 SafeMode(String),
115
116 #[error("Authentication operation failed: {0}")]
118 AuthOperation(String),
119
120 #[error("No witnesses found for subject '{0}'")]
122 WitnessesNotFound(String),
123
124 #[error("Query failed: {0}")]
129 QueryFailed(String),
130
131 #[error("No events found for subject '{0}'")]
133 NoEventsFound(String),
134
135 #[error("Event not found for subject '{subject}' at sequence number {sn}")]
137 EventNotFound { subject: String, sn: u64 },
138
139 #[error("Invalid query parameters: {0}")]
141 InvalidQueryParams(String),
142
143 #[error("Database error: {0}")]
145 DatabaseError(String),
146
147 #[error("Validation failed: {0}")]
152 ValidationFailed(String),
153
154 #[error("Invalid event request: {0}")]
156 InvalidEventRequest(String),
157
158 #[error("Schema validation failed: {0}")]
160 SchemaValidation(String),
161
162 #[error("Internal communication error: failed to communicate with {actor}")]
167 ActorCommunication { actor: String },
168
169 #[error(
171 "Unexpected response from {actor}: expected {expected}, got {received}"
172 )]
173 UnexpectedResponse {
174 actor: String,
175 expected: String,
176 received: String,
177 },
178
179 #[error("Operation failed: {0}")]
181 ActorError(String),
182
183 #[error("Transfer operation failed: {0}")]
188 TransferFailed(String),
189
190 #[error("No pending transfers found")]
192 NoPendingTransfers,
193
194 #[error("Manual distribution failed for subject '{0}'")]
199 DistributionFailed(String),
200
201 #[error("Update failed for subject '{0}': {1}")]
203 UpdateFailed(String, String),
204
205 #[error("Internal error: {0}")]
210 Internal(String),
211
212 #[error("Operation timed out: {0}")]
214 Timeout(String),
215
216 #[error("Feature not implemented: {0}")]
218 NotImplemented(String),
219}
220
221impl From<crate::system::SystemError> for Error {
223 fn from(err: crate::system::SystemError) -> Self {
224 Self::SystemInit(err.to_string())
225 }
226}
227
228impl From<ave_actors::ActorError> for Error {
229 fn from(err: ave_actors::ActorError) -> Self {
230 match err {
231 ave_actors::ActorError::NotFound { path } => {
232 Self::MissingResource {
233 name: path.to_string(),
234 reason: "Actor not found".to_string(),
235 }
236 }
237 ave_actors::ActorError::Functional { description } => {
238 Self::ActorError(description)
239 }
240 ave_actors::ActorError::FunctionalCritical { description } => {
241 Self::Internal(description)
242 }
243 _ => Self::Internal(err.to_string()),
244 }
245 }
246}