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("Invalid subject identifier: {0}")]
92 InvalidSubjectId(String),
93
94 #[error("Authorization failed: {0}")]
99 Unauthorized(String),
100
101 #[error("Insufficient permissions: {0}")]
103 Forbidden(String),
104
105 #[error("Authentication operation failed: {0}")]
107 AuthOperation(String),
108
109 #[error("No witnesses found for subject '{0}'")]
111 WitnessesNotFound(String),
112
113 #[error("Query failed: {0}")]
118 QueryFailed(String),
119
120 #[error("No events found for subject '{0}'")]
122 NoEventsFound(String),
123
124 #[error("Event not found for subject '{subject}' at sequence number {sn}")]
126 EventNotFound { subject: String, sn: u64 },
127
128 #[error("Invalid query parameters: {0}")]
130 InvalidQueryParams(String),
131
132 #[error("Database error: {0}")]
134 DatabaseError(String),
135
136 #[error("Validation failed: {0}")]
141 ValidationFailed(String),
142
143 #[error("Invalid event request: {0}")]
145 InvalidEventRequest(String),
146
147 #[error("Schema validation failed: {0}")]
149 SchemaValidation(String),
150
151 #[error("Internal communication error: failed to communicate with {actor}")]
156 ActorCommunication { actor: String },
157
158 #[error(
160 "Unexpected response from {actor}: expected {expected}, got {received}"
161 )]
162 UnexpectedResponse {
163 actor: String,
164 expected: String,
165 received: String,
166 },
167
168 #[error("Operation failed: {0}")]
170 ActorError(String),
171
172 #[error("Transfer operation failed: {0}")]
177 TransferFailed(String),
178
179 #[error("No pending transfers found")]
181 NoPendingTransfers,
182
183 #[error("Manual distribution failed for subject '{0}'")]
188 DistributionFailed(String),
189
190 #[error("Update failed for subject '{0}': {1}")]
192 UpdateFailed(String, String),
193
194 #[error("Internal error: {0}")]
199 Internal(String),
200
201 #[error("Operation timed out: {0}")]
203 Timeout(String),
204
205 #[error("Feature not implemented: {0}")]
207 NotImplemented(String),
208}
209
210impl From<crate::system::SystemError> for Error {
212 fn from(err: crate::system::SystemError) -> Self {
213 Self::SystemInit(err.to_string())
214 }
215}
216
217impl From<ave_actors::ActorError> for Error {
218 fn from(err: ave_actors::ActorError) -> Self {
219 match err {
220 ave_actors::ActorError::NotFound { path } => {
221 Self::MissingResource {
222 name: path.to_string(),
223 reason: "Actor not found".to_string(),
224 }
225 }
226 ave_actors::ActorError::Functional { description } => {
227 Self::ActorError(description)
228 }
229 ave_actors::ActorError::FunctionalCritical { description } => {
230 Self::Internal(description)
231 }
232 _ => Self::Internal(err.to_string()),
233 }
234 }
235}