Skip to main content

alien_core/
error.rs

1use alien_error::AlienErrorData;
2use serde::{Deserialize, Serialize};
3
4use crate::{Platform, ResourceType};
5
6/// Core error data exposed by the `alien-core` crate.
7#[derive(Debug, Clone, AlienErrorData, Serialize, Deserialize)]
8#[serde(rename_all = "camelCase")]
9pub enum ErrorData {
10    /// An applicable stack input is missing or violates its declared constraints.
11    #[error(
12        code = "STACK_INPUT_INVALID",
13        message = "Stack input '{input_id}': {reason}",
14        retryable = "false",
15        internal = "false",
16        http_status_code = 400
17    )]
18    StackInputInvalid { input_id: String, reason: String },
19
20    /// A stack definition field written in authoring shorthand cannot be resolved.
21    #[error(
22        code = "STACK_DEFINITION_INVALID",
23        message = "Invalid {field}: {reason}",
24        retryable = "false",
25        internal = "false",
26        http_status_code = 400
27    )]
28    StackDefinitionInvalid {
29        /// Authoring path of the field, as the TypeScript SDK names it (for example `dataDisk.size.min`).
30        field: String,
31        /// Why the value cannot be used.
32        reason: String,
33    },
34
35    /// Federation metadata cannot safely identify the intended trust or target.
36    #[error(
37        code = "GCP_FEDERATION_INVALID",
38        message = "Invalid GCP federation field '{field}': {reason}",
39        retryable = "false",
40        internal = "false",
41        http_status_code = 400
42    )]
43    GcpFederationInvalid { field: String, reason: String },
44
45    /// The image's command identity cannot be resolved safely.
46    #[error(
47        code = "SANDBOX_IMAGE_USER_INVALID",
48        message = "Invalid sandbox image USER '{user}': {reason}",
49        retryable = "false",
50        internal = "false",
51        http_status_code = 400
52    )]
53    SandboxImageUserInvalid { user: String, reason: String },
54    /// Policy exceeds the portable target-count or canonical JSON size limit.
55    #[error(
56        code = "SANDBOX_EGRESS_POLICY_TOO_LARGE",
57        message = "Sandbox egress policy exceeds {limit}",
58        retryable = "false",
59        internal = "false",
60        http_status_code = 400
61    )]
62    SandboxEgressPolicyTooLarge { limit: String },
63
64    /// An egress target cannot be enforced safely.
65    #[error(
66        code = "SANDBOX_EGRESS_INVALID",
67        message = "Invalid sandbox egress target '{target}': {reason}",
68        retryable = "false",
69        internal = "false",
70        http_status_code = 400
71    )]
72    SandboxEgressInvalid { target: String, reason: String },
73
74    /// An AWS internet sandbox reached template rendering without the egress gateway.
75    #[error(
76        code = "SANDBOX_INTERNET_GATEWAY_MISSING",
77        message = "Sandbox '{sandbox_id}' declares egress 'internet', which routes through the managed sandbox egress gateway, but this stack has no gateway. Prepare the stack with the deployment preflights before rendering its setup template",
78        retryable = "false",
79        internal = "false"
80    )]
81    SandboxInternetGatewayMissing { sandbox_id: String },
82
83    /// A deployment selected resources outside the release's declared choices.
84    #[error(
85        code = "CONTAINER_RESOURCE_SELECTION_INVALID",
86        message = "Invalid {dimension} selection for container '{resource_id}': {reason}",
87        retryable = "false",
88        internal = "false",
89        http_status_code = 400
90    )]
91    ContainerResourceSelectionInvalid {
92        resource_id: String,
93        dimension: String,
94        reason: String,
95    },
96    /// A fallback error when nothing more specific matches.
97    #[error(
98        code = "GENERIC_ERROR",
99        message = "{message}",
100        retryable = "true",
101        internal = "false"
102    )]
103    GenericError {
104        /// Human-readable description of the error.
105        message: String,
106    },
107
108    /// Resource type mismatch found during stack operations.
109    #[error(
110        code = "UNEXPECTED_RESOURCE_TYPE",
111        message = "Unexpected resource type for resource '{resource_id}': expected {expected}, but got {actual}",
112        retryable = "false",
113        internal = "false"
114    )]
115    UnexpectedResourceType {
116        resource_id: String,
117        expected: ResourceType,
118        actual: ResourceType,
119    },
120
121    /// Attempt to update a resource that does not support updates.
122    #[error(
123        code = "INVALID_RESOURCE_UPDATE",
124        message = "Resource '{resource_id}' cannot be updated: {reason}",
125        retryable = "false",
126        internal = "false"
127    )]
128    InvalidResourceUpdate { resource_id: String, reason: String },
129
130    /// Worker execution timeout is outside the supported range.
131    #[error(
132        code = "WORKER_TIMEOUT_INVALID",
133        message = "Worker timeoutSeconds must be between 1 and {max_timeout_seconds} seconds, got {timeout_seconds}",
134        retryable = "false",
135        internal = "false",
136        http_status_code = 400
137    )]
138    WorkerTimeoutInvalid {
139        timeout_seconds: u32,
140        max_timeout_seconds: u32,
141    },
142
143    /// The resource exists but has not produced any outputs yet.
144    #[error(
145        code = "RESOURCE_HAS_NO_OUTPUTS",
146        message = "Resource '{resource_id}' has no outputs",
147        retryable = "true",
148        internal = "false"
149    )]
150    ResourceHasNoOutputs { resource_id: String },
151
152    /// Requested resource absent from the stack state.
153    #[error(
154        code = "RESOURCE_NOT_FOUND",
155        message = "Resource '{resource_id}' not found in stack state. Available resources: {available_resources:?}",
156        retryable = "false",
157        internal = "false",
158        http_status_code = 404
159    )]
160    ResourceNotFound {
161        resource_id: String,
162        available_resources: Vec<String>,
163    },
164
165    /// Binding configuration is invalid or missing required fields.
166    #[error(
167        code = "BINDING_CONFIG_INVALID",
168        message = "Invalid binding configuration for '{binding_name}': {reason}",
169        retryable = "false",
170        internal = "false"
171    )]
172    BindingConfigInvalid {
173        binding_name: String,
174        reason: String,
175    },
176
177    /// Environment variable for binding is missing.
178    #[error(
179        code = "BINDING_ENV_VAR_MISSING",
180        message = "Missing environment variable '{env_var}' for binding '{binding_name}'",
181        retryable = "false",
182        internal = "false"
183    )]
184    BindingEnvVarMissing {
185        binding_name: String,
186        env_var: String,
187    },
188
189    /// Failed to parse binding JSON from environment variable.
190    #[error(
191        code = "BINDING_JSON_PARSE_FAILED",
192        message = "Failed to parse binding JSON for '{binding_name}': {reason}",
193        retryable = "false",
194        internal = "false"
195    )]
196    BindingJsonParseFailed {
197        binding_name: String,
198        reason: String,
199    },
200
201    /// Unexpected combination of resource statuses when computing stack status.
202    #[error(
203        code = "UNEXPECTED_RESOURCE_STATUS_COMBINATION",
204        message = "Unexpected resource status combination during {operation}: {resource_statuses:?}",
205        retryable = "false",
206        internal = "true"
207    )]
208    UnexpectedResourceStatusCombination {
209        resource_statuses: Vec<String>,
210        operation: String,
211    },
212
213    /// External binding type does not match the resource type.
214    #[error(
215        code = "EXTERNAL_BINDING_TYPE_MISMATCH",
216        message = "External binding type mismatch for resource '{resource_id}': expected {expected}, got {actual}",
217        retryable = "false",
218        internal = "false"
219    )]
220    ExternalBindingTypeMismatch {
221        resource_id: String,
222        expected: String,
223        actual: String,
224    },
225
226    // Presigned request errors
227    /// Presigned request has expired.
228    #[error(
229        code = "PRESIGNED_REQUEST_EXPIRED",
230        message = "Presigned request for '{path}' expired at {expired_at}",
231        retryable = "false",
232        internal = "false"
233    )]
234    PresignedRequestExpired {
235        path: String,
236        expired_at: chrono::DateTime<chrono::Utc>,
237    },
238
239    /// HTTP request failed.
240    #[error(
241        code = "HTTP_REQUEST_FAILED",
242        message = "HTTP {method} request to '{url}' failed",
243        retryable = "true",
244        internal = "false"
245    )]
246    HttpRequestFailed { url: String, method: String },
247
248    /// Operation not supported.
249    #[error(
250        code = "OPERATION_NOT_SUPPORTED",
251        message = "Operation '{operation}' not supported: {reason}",
252        retryable = "false",
253        internal = "false"
254    )]
255    OperationNotSupported { operation: String, reason: String },
256
257    /// Setup cannot put a resource where the chosen cluster could use it.
258    #[error(
259        code = "SETUP_PLACEMENT_UNSUPPORTED",
260        message = "{message}",
261        retryable = "false",
262        internal = "false",
263        http_status_code = 422
264    )]
265    SetupPlacementUnsupported {
266        /// What to change, in plain words.
267        message: String,
268        /// Type of the resource that cannot be placed.
269        resource_type: String,
270        /// Id of the resource that cannot be placed.
271        resource_id: String,
272    },
273
274    /// Local filesystem error.
275    #[error(
276        code = "LOCAL_FILESYSTEM_ERROR",
277        message = "Local filesystem error for '{path}' during {operation}",
278        retryable = "false",
279        internal = "false"
280    )]
281    LocalFilesystemError { path: String, operation: String },
282
283    /// Feature not enabled.
284    #[error(
285        code = "FEATURE_NOT_ENABLED",
286        message = "Feature '{feature}' is not enabled",
287        retryable = "false",
288        internal = "false"
289    )]
290    FeatureNotEnabled { feature: String },
291
292    /// A resource requires setup capabilities unavailable to automatic management.
293    #[error(
294        code = "AUTOMATIC_SETUP_RESOURCE_UNSUPPORTED",
295        message = "Automatic infrastructure management does not support {resource_type} '{resource_id}' on {platform}; use manual setup",
296        retryable = "false",
297        internal = "false",
298        http_status_code = 400
299    )]
300    AutomaticSetupResourceUnsupported {
301        resource_type: String,
302        resource_id: String,
303        platform: Platform,
304    },
305
306    /// A sandbox capability is unavailable on the target platform.
307    #[error(
308        code = "SANDBOX_CAPABILITY_UNSUPPORTED",
309        message = "Sandbox capability '{capability}' is not supported on {platform}",
310        retryable = "false",
311        internal = "false",
312        http_status_code = 400
313    )]
314    SandboxCapabilityUnsupported {
315        /// The capability that was requested
316        capability: String,
317        /// The platform that does not offer it
318        platform: String,
319    },
320
321    /// The target platform has no sandbox backend at all.
322    #[error(
323        code = "SANDBOX_PLATFORM_UNSUPPORTED",
324        message = "Sandbox is not available on {platform}",
325        retryable = "false",
326        internal = "false",
327        http_status_code = 400
328    )]
329    SandboxPlatformUnsupported {
330        /// The platform with no sandbox backend
331        platform: String,
332    },
333
334    /// A bundle signature or signing key was rejected.
335    #[error(
336        code = "BUNDLE_SIGNATURE_INVALID",
337        message = "Bundle signature invalid: {reason}",
338        retryable = "false",
339        internal = "false",
340        http_status_code = 400
341    )]
342    BundleSignatureInvalid {
343        /// Why the signature or key was rejected
344        reason: String,
345    },
346
347    /// A release signing key was rejected.
348    #[error(
349        code = "RELEASE_SIGNING_KEY_INVALID",
350        message = "Release signing key invalid: {reason}",
351        retryable = "false",
352        internal = "false",
353        http_status_code = 400
354    )]
355    ReleaseSigningKeyInvalid {
356        /// Why the key was rejected
357        reason: String,
358    },
359
360    /// The stack's signing setting can't become the install's signing settings.
361    #[error(
362        code = "SIGNING_SETTINGS_INVALID",
363        message = "Signing settings invalid: {reason}",
364        retryable = "false",
365        internal = "false",
366        http_status_code = 400
367    )]
368    SigningSettingsInvalid {
369        /// Why the settings were refused
370        reason: String,
371    },
372
373    /// A release statement could not be built or signed.
374    #[error(
375        code = "RELEASE_STATEMENT_INVALID",
376        message = "Release statement invalid: {reason}",
377        retryable = "false",
378        internal = "false",
379        http_status_code = 400
380    )]
381    ReleaseStatementInvalid {
382        /// Why the statement could not be built
383        reason: String,
384    },
385
386    /// A sandbox capability was refused.
387    #[error(
388        code = "SANDBOX_CAPABILITY_REFUSED",
389        message = "Sandbox capability refused: {reason}",
390        retryable = "false",
391        internal = "false",
392        http_status_code = 403
393    )]
394    SandboxCapabilityRefused {
395        /// Why it was refused. Deliberately coarse — it must not reveal which sandboxes exist.
396        reason: String,
397    },
398
399    /// A sandbox limit is missing or not a valid quantity.
400    #[error(
401        code = "SANDBOX_LIMIT_INVALID",
402        message = "Sandbox '{resource_id}' has an invalid {field} limit '{value}': {reason}",
403        retryable = "false",
404        internal = "false",
405        http_status_code = 400
406    )]
407    SandboxLimitInvalid {
408        /// The sandbox whose limit failed validation
409        resource_id: String,
410        /// Which limit (cpu, memory, disk, maxProcesses)
411        field: String,
412        /// The rejected value
413        value: String,
414        /// Why it was rejected
415        reason: String,
416    },
417
418    // Commands protocol errors
419    /// Invalid Commands envelope.
420    #[error(
421        code = "INVALID_ENVELOPE",
422        message = "Invalid Commands envelope: {message}",
423        retryable = "false",
424        internal = "false"
425    )]
426    InvalidEnvelope {
427        message: String,
428        field: Option<String>,
429    },
430
431    /// A command-enabled resource exists but the deployment has no token to
432    /// authenticate its command transport.
433    #[error(
434        code = "COMMAND_TOKEN_MISSING",
435        message = "Deployment has command-enabled resource '{resource_id}' but no deployment token to authenticate it: {reason}",
436        retryable = "false",
437        internal = "false"
438    )]
439    CommandTokenMissing { resource_id: String, reason: String },
440
441    /// Public URL configuration is invalid.
442    #[error(
443        code = "PUBLIC_URL_INVALID",
444        message = "Invalid public URL for resource '{resource_id}': {reason}",
445        retryable = "false",
446        internal = "false",
447        http_status_code = 400
448    )]
449    PublicUrlInvalid { resource_id: String, reason: String },
450
451    /// JSON serialization failed.
452    #[error(
453        code = "JSON_SERIALIZATION_FAILED",
454        message = "Failed to serialize JSON: {reason}",
455        retryable = "false",
456        internal = "false"
457    )]
458    JsonSerializationFailed { reason: String },
459
460    /// JSON deserialization failed.
461    #[error(
462        code = "JSON_DESERIALIZATION_FAILED",
463        message = "Failed to deserialize JSON: {reason}",
464        retryable = "false",
465        internal = "false"
466    )]
467    JsonDeserializationFailed { reason: String },
468
469    /// Distribution template serialization failed.
470    #[error(
471        code = "TEMPLATE_SERIALIZATION_FAILED",
472        message = "Failed to serialize {format} template: {reason}",
473        retryable = "false",
474        internal = "true"
475    )]
476    TemplateSerializationFailed { format: String, reason: String },
477
478    /// A management ExternalId is not 32 to 128 ASCII letters and digits.
479    #[error(
480        code = "MANAGEMENT_EXTERNAL_ID_INVALID",
481        message = "Management ExternalId must be 32 to 128 ASCII letters and digits (got {length} characters)",
482        retryable = "false",
483        internal = "false",
484        http_status_code = 400
485    )]
486    ManagementExternalIdInvalid {
487        /// Length of the rejected value. The value itself is never echoed.
488        length: usize,
489    },
490
491    /// A role ARN a setup template is told to accept as its managing role is
492    /// not an IAM role ARN.
493    #[error(
494        code = "MANAGING_ROLE_ARN_INVALID",
495        message = "Managing role ARN '{arn}' is not an IAM role ARN (arn:<partition>:iam::<account>:role/<name>)",
496        retryable = "false",
497        internal = "false",
498        http_status_code = 400
499    )]
500    ManagingRoleArnInvalid {
501        /// The rejected ARN.
502        arn: String,
503    },
504
505    /// ImportData did not match the registered typed payload.
506    #[error(
507        code = "IMPORT_DATA_INVALID",
508        message = "Invalid ImportData for resource '{resource_id}' ({resource_type}) on {platform}",
509        retryable = "false",
510        internal = "false",
511        http_status_code = 400
512    )]
513    ImportDataInvalid {
514        resource_id: String,
515        resource_type: ResourceType,
516        platform: Platform,
517    },
518
519    /// No registry implementation exists for a resource/platform pair.
520    #[error(
521        code = "IMPORT_REGISTRATION_MISSING",
522        message = "Missing {registration_kind} registration for resource type '{resource_type}' on {platform}",
523        retryable = "false",
524        internal = "true"
525    )]
526    ImportRegistrationMissing {
527        resource_type: ResourceType,
528        platform: Platform,
529        registration_kind: String,
530    },
531
532    /// ImportData schema serialization failed.
533    #[error(
534        code = "IMPORT_SCHEMA_SERIALIZATION_FAILED",
535        message = "Failed to serialize ImportData schema",
536        retryable = "false",
537        internal = "true"
538    )]
539    ImportSchemaSerializationFailed,
540}
541
542pub type Result<T> = alien_error::Result<T, ErrorData>;