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