alien_commands/error.rs
1use alien_error::{AlienError, AlienErrorData};
2use serde::{Deserialize, Serialize};
3
4/// Errors that occur in the commands protocol.
5#[derive(Debug, Clone, AlienErrorData, Serialize, Deserialize)]
6#[serde(rename_all = "camelCase")]
7pub enum ErrorData {
8 /// Command validation failed or contains invalid data.
9 #[error(
10 code = "INVALID_COMMAND",
11 message = "Invalid command: {message}",
12 retryable = "false",
13 internal = "false",
14 http_status_code = 400
15 )]
16 InvalidCommand {
17 /// Human-readable description of what makes the command invalid
18 message: String,
19 },
20
21 /// Requested command ID was not found.
22 #[error(
23 code = "COMMAND_NOT_FOUND",
24 message = "Command '{command_id}' not found",
25 retryable = "false",
26 internal = "false",
27 http_status_code = 404
28 )]
29 CommandNotFound {
30 /// ID of the command that was not found
31 command_id: String,
32 },
33
34 /// The manager serving a hosted command capability no longer owns its
35 /// deployment. Clients should refresh bootstrap discovery and retry.
36 #[error(
37 code = "COMMAND_CONNECTION_STALE",
38 message = "Command connection is stale for '{resource}'",
39 retryable = "true",
40 internal = "false",
41 http_status_code = 401
42 )]
43 CommandConnectionStale {
44 /// Deployment or command identifier whose manager assignment changed
45 resource: String,
46 },
47
48 /// Explicitly requested command target does not exist in the deployment
49 /// (or is not command-capable). Also returned for an empty resource id.
50 ///
51 /// 404 mirrors the crate's other lookup failures (COMMAND_NOT_FOUND,
52 /// LEASE_NOT_FOUND): the named resource does not exist.
53 #[error(
54 code = "COMMAND_TARGET_NOT_FOUND",
55 message = "Command target '{resource_id}' not found in deployment '{deployment_id}'",
56 retryable = "false",
57 internal = "false",
58 http_status_code = 404
59 )]
60 CommandTargetNotFound {
61 /// Resource ID that was requested but not found
62 resource_id: String,
63 /// Deployment the target was looked up in
64 deployment_id: String,
65 },
66
67 /// Single-target shorthand was used but the deployment has multiple
68 /// command-capable targets.
69 ///
70 /// 409 mirrors CONFLICT: the request conflicts with the deployment's
71 /// current state and the client resolves it by naming a target.
72 #[error(
73 code = "COMMAND_TARGET_AMBIGUOUS",
74 message = "Deployment '{deployment_id}' has multiple command-capable targets; specify targetResourceId",
75 retryable = "false",
76 internal = "false",
77 http_status_code = 409
78 )]
79 CommandTargetAmbiguous {
80 /// Deployment with more than one command-capable target
81 deployment_id: String,
82 },
83
84 /// The deployment has no command-capable targets at all.
85 ///
86 /// 422: the request is well-formed but unsatisfiable for this deployment
87 /// (no resource has commands enabled) — unlike 400 (malformed) or 404
88 /// (a specific named thing missing).
89 #[error(
90 code = "NO_COMMAND_TARGETS",
91 message = "Deployment '{deployment_id}' has no command-capable targets",
92 retryable = "false",
93 internal = "false",
94 http_status_code = 422
95 )]
96 NoCommandTargets {
97 /// Deployment without any command-capable targets
98 deployment_id: String,
99 },
100
101 /// A command target resource id contains `:`, which would break the
102 /// pending-index and idempotency-key delimiter grammar.
103 ///
104 /// 400: the request (or a stored target) is malformed. The commands layer
105 /// permits every resource-id character except `:`, which delimits key
106 /// segments.
107 #[error(
108 code = "COMMAND_TARGET_ID_INVALID",
109 message = "Command target id '{resource_id}' is invalid: ids cannot contain ':'",
110 retryable = "false",
111 internal = "false",
112 http_status_code = 400
113 )]
114 CommandTargetIdInvalid {
115 /// The offending resource id
116 resource_id: String,
117 },
118
119 /// Pull command receiver configuration from the environment is missing
120 /// or invalid (e.g. a required `ALIEN_COMMANDS_*` variable is absent).
121 #[error(
122 code = "COMMAND_RECEIVER_CONFIG_INVALID",
123 message = "Command receiver configuration invalid: {message}",
124 retryable = "false",
125 internal = "false",
126 http_status_code = 400
127 )]
128 CommandReceiverConfigInvalid {
129 /// Human-readable description of what is missing or invalid
130 message: String,
131 /// Environment variable that is missing or invalid
132 env_var: String,
133 },
134
135 /// The command receiver bearer token was rejected by the commands API.
136 #[error(
137 code = "COMMAND_RECEIVER_UNAUTHORIZED",
138 message = "Command receiver authorization failed during {operation}",
139 retryable = "false",
140 internal = "false",
141 http_status_code = 401
142 )]
143 CommandReceiverUnauthorized {
144 /// Command API operation that was rejected
145 operation: String,
146 /// Commands API URL that rejected the token
147 url: String,
148 },
149
150 /// The command receiver request was permanently rejected by the commands API.
151 #[error(
152 code = "COMMAND_RECEIVER_REQUEST_REJECTED",
153 message = "Command receiver request was rejected with HTTP {status} during {operation}",
154 retryable = "false",
155 internal = "false",
156 http_status_code = 502
157 )]
158 CommandReceiverRequestRejected {
159 /// Command API operation that was rejected
160 operation: String,
161 /// HTTP status returned by the commands API
162 status: u16,
163 /// Commands API URL that rejected the request
164 url: String,
165 },
166
167 /// Invalid state transition attempted on command.
168 #[error(
169 code = "INVALID_STATE_TRANSITION",
170 message = "Invalid state transition from '{from}' to '{to}'",
171 retryable = "false",
172 internal = "false",
173 http_status_code = 400
174 )]
175 InvalidStateTransition {
176 /// Current state of the command
177 from: String,
178 /// Attempted new state
179 to: String,
180 },
181
182 /// Command has expired and can no longer be processed.
183 #[error(
184 code = "COMMAND_EXPIRED",
185 message = "Command '{command_id}' has expired",
186 retryable = "false",
187 internal = "false",
188 http_status_code = 410
189 )]
190 CommandExpired {
191 /// ID of the expired command
192 command_id: String,
193 },
194
195 /// Storage backend operation failed.
196 #[error(
197 code = "STORAGE_OPERATION_FAILED",
198 message = "Storage operation failed: {message}",
199 retryable = "true",
200 internal = "false"
201 )]
202 StorageOperationFailed {
203 /// Human-readable description of the storage failure
204 message: String,
205 /// Storage operation type (upload, download, etc.)
206 operation: Option<String>,
207 /// Storage path or URL that failed
208 path: Option<String>,
209 },
210
211 /// Key-value store operation failed.
212 #[error(
213 code = "KV_OPERATION_FAILED",
214 message = "KV operation '{operation}' failed on key '{key}': {message}",
215 retryable = "true",
216 internal = "false"
217 )]
218 KvOperationFailed {
219 /// Type of KV operation that failed
220 operation: String,
221 /// Key that was being operated on
222 key: String,
223 /// Human-readable description of the failure
224 message: String,
225 },
226
227 /// Transport dispatch to agent failed.
228 #[error(
229 code = "TRANSPORT_DISPATCH_FAILED",
230 message = "Transport dispatch failed: {message}",
231 retryable = "true",
232 internal = "false"
233 )]
234 TransportDispatchFailed {
235 /// Human-readable description of the dispatch failure
236 message: String,
237 /// Transport type that failed
238 transport_type: Option<String>,
239 /// Target endpoint or agent identifier
240 target: Option<String>,
241 },
242
243 /// Transport rejected a command before accepting it for execution.
244 ///
245 /// Unlike an acknowledgement timeout, this is a definite non-delivery:
246 /// the command server may safely record a terminal delivery failure.
247 #[error(
248 code = "TRANSPORT_DISPATCH_REJECTED",
249 message = "Transport rejected dispatch: {message}",
250 retryable = "false",
251 internal = "false"
252 )]
253 TransportDispatchRejected {
254 /// Safe description that contains no endpoint credentials or body.
255 message: String,
256 /// Transport type that rejected the command.
257 transport_type: Option<String>,
258 /// Command identifier (never a credential-bearing URL).
259 target: Option<String>,
260 },
261
262 /// Command envelope validation or parsing failed.
263 #[error(
264 code = "INVALID_ENVELOPE",
265 message = "Invalid command envelope: {message}",
266 retryable = "false",
267 internal = "false",
268 http_status_code = 400
269 )]
270 InvalidEnvelope {
271 /// Human-readable description of the envelope issue
272 message: String,
273 /// Envelope field that caused the validation failure
274 field: Option<String>,
275 },
276
277 /// Agent reported an error during command processing.
278 #[error(
279 code = "AGENT_ERROR",
280 message = "Agent error: {message}",
281 retryable = "true",
282 internal = "false"
283 )]
284 AgentError {
285 /// Human-readable description of the agent error
286 message: String,
287 /// Agent identifier if available
288 deployment_id: Option<String>,
289 },
290
291 /// Serialization or deserialization operation failed.
292 #[error(
293 code = "SERIALIZATION_FAILED",
294 message = "Serialization failed: {message}",
295 retryable = "false",
296 internal = "true"
297 )]
298 SerializationFailed {
299 /// Human-readable description of the serialization failure
300 message: String,
301 /// Data type that failed to serialize/deserialize
302 data_type: Option<String>,
303 },
304
305 /// HTTP operation failed during command processing.
306 #[error(
307 code = "HTTP_OPERATION_FAILED",
308 message = "HTTP operation failed: {message}",
309 retryable = "true",
310 internal = "false"
311 )]
312 HttpOperationFailed {
313 /// Human-readable description of the HTTP failure
314 message: String,
315 /// HTTP method if available
316 method: Option<String>,
317 /// URL that failed if available
318 url: Option<String>,
319 },
320
321 /// Operation is not supported by the current configuration.
322 #[error(
323 code = "OPERATION_NOT_SUPPORTED",
324 message = "Operation not supported: {message}",
325 retryable = "false",
326 internal = "false",
327 http_status_code = 501
328 )]
329 OperationNotSupported {
330 /// Human-readable description of what operation is not supported
331 message: String,
332 /// Operation type that was attempted
333 operation: Option<String>,
334 },
335
336 /// Resource conflict detected (e.g., concurrent modification).
337 #[error(
338 code = "CONFLICT",
339 message = "Conflict: {message}",
340 retryable = "true",
341 internal = "false",
342 http_status_code = 409
343 )]
344 Conflict {
345 /// Human-readable description of the conflict
346 message: String,
347 /// Resource identifier that has the conflict
348 resource_id: Option<String>,
349 },
350
351 /// Requested lease ID was not found.
352 #[error(
353 code = "LEASE_NOT_FOUND",
354 message = "Lease '{lease_id}' not found",
355 retryable = "false",
356 internal = "false",
357 http_status_code = 404
358 )]
359 LeaseNotFound {
360 /// ID of the lease that was not found
361 lease_id: String,
362 },
363
364 /// Generic commands error for uncommon cases.
365 #[error(
366 code = "COMMANDS_ERROR",
367 message = "Commands protocol error: {message}",
368 retryable = "true",
369 internal = "true"
370 )]
371 Other {
372 /// Human-readable description of the error
373 message: String,
374 },
375}
376
377pub type Error = AlienError<ErrorData>;
378pub type Result<T> = alien_error::Result<T, ErrorData>;