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 rendered Helm chart a check refuses: an object it can't read, or one an extension
97    /// renders that collides with another.
98    #[error(
99        code = "RENDERED_CHART_REFUSED",
100        message = "{reason}",
101        retryable = "false",
102        internal = "false"
103    )]
104    RenderedChartRefused {
105        /// Why the chart is refused
106        reason: String,
107    },
108
109    /// A fallback error when nothing more specific matches.
110    #[error(
111        code = "GENERIC_ERROR",
112        message = "{message}",
113        retryable = "true",
114        internal = "false"
115    )]
116    GenericError {
117        /// Human-readable description of the error.
118        message: String,
119    },
120
121    /// Resource type mismatch found during stack operations.
122    #[error(
123        code = "UNEXPECTED_RESOURCE_TYPE",
124        message = "Unexpected resource type for resource '{resource_id}': expected {expected}, but got {actual}",
125        retryable = "false",
126        internal = "false"
127    )]
128    UnexpectedResourceType {
129        resource_id: String,
130        expected: ResourceType,
131        actual: ResourceType,
132    },
133
134    /// Attempt to update a resource that does not support updates.
135    #[error(
136        code = "INVALID_RESOURCE_UPDATE",
137        message = "Resource '{resource_id}' cannot be updated: {reason}",
138        retryable = "false",
139        internal = "false"
140    )]
141    InvalidResourceUpdate { resource_id: String, reason: String },
142
143    /// Worker execution timeout is outside the supported range.
144    #[error(
145        code = "WORKER_TIMEOUT_INVALID",
146        message = "Worker timeoutSeconds must be between 1 and {max_timeout_seconds} seconds, got {timeout_seconds}",
147        retryable = "false",
148        internal = "false",
149        http_status_code = 400
150    )]
151    WorkerTimeoutInvalid {
152        timeout_seconds: u32,
153        max_timeout_seconds: u32,
154    },
155
156    /// The resource exists but has not produced any outputs yet.
157    #[error(
158        code = "RESOURCE_HAS_NO_OUTPUTS",
159        message = "Resource '{resource_id}' has no outputs",
160        retryable = "true",
161        internal = "false"
162    )]
163    ResourceHasNoOutputs { resource_id: String },
164
165    /// Requested resource absent from the stack state.
166    #[error(
167        code = "RESOURCE_NOT_FOUND",
168        message = "Resource '{resource_id}' not found in stack state. Available resources: {available_resources:?}",
169        retryable = "false",
170        internal = "false",
171        http_status_code = 404
172    )]
173    ResourceNotFound {
174        resource_id: String,
175        available_resources: Vec<String>,
176    },
177
178    /// Binding configuration is invalid or missing required fields.
179    #[error(
180        code = "BINDING_CONFIG_INVALID",
181        message = "Invalid binding configuration for '{binding_name}': {reason}",
182        retryable = "false",
183        internal = "false"
184    )]
185    BindingConfigInvalid {
186        binding_name: String,
187        reason: String,
188    },
189
190    /// Environment variable for binding is missing.
191    #[error(
192        code = "BINDING_ENV_VAR_MISSING",
193        message = "Missing environment variable '{env_var}' for binding '{binding_name}'",
194        retryable = "false",
195        internal = "false"
196    )]
197    BindingEnvVarMissing {
198        binding_name: String,
199        env_var: String,
200    },
201
202    /// Failed to parse binding JSON from environment variable.
203    #[error(
204        code = "BINDING_JSON_PARSE_FAILED",
205        message = "Failed to parse binding JSON for '{binding_name}': {reason}",
206        retryable = "false",
207        internal = "false"
208    )]
209    BindingJsonParseFailed {
210        binding_name: String,
211        reason: String,
212    },
213
214    /// Unexpected combination of resource statuses when computing stack status.
215    #[error(
216        code = "UNEXPECTED_RESOURCE_STATUS_COMBINATION",
217        message = "Unexpected resource status combination during {operation}: {resource_statuses:?}",
218        retryable = "false",
219        internal = "true"
220    )]
221    UnexpectedResourceStatusCombination {
222        resource_statuses: Vec<String>,
223        operation: String,
224    },
225
226    /// External binding type does not match the resource type.
227    #[error(
228        code = "EXTERNAL_BINDING_TYPE_MISMATCH",
229        message = "External binding type mismatch for resource '{resource_id}': expected {expected}, got {actual}",
230        retryable = "false",
231        internal = "false"
232    )]
233    ExternalBindingTypeMismatch {
234        resource_id: String,
235        expected: String,
236        actual: String,
237    },
238
239    // Presigned request errors
240    /// Presigned request has expired.
241    #[error(
242        code = "PRESIGNED_REQUEST_EXPIRED",
243        message = "Presigned request for '{path}' expired at {expired_at}",
244        retryable = "false",
245        internal = "false"
246    )]
247    PresignedRequestExpired {
248        path: String,
249        expired_at: chrono::DateTime<chrono::Utc>,
250    },
251
252    /// HTTP request failed.
253    #[error(
254        code = "HTTP_REQUEST_FAILED",
255        message = "HTTP {method} request to '{url}' failed",
256        retryable = "true",
257        internal = "false"
258    )]
259    HttpRequestFailed { url: String, method: String },
260
261    /// Operation not supported.
262    #[error(
263        code = "OPERATION_NOT_SUPPORTED",
264        message = "Operation '{operation}' not supported: {reason}",
265        retryable = "false",
266        internal = "false"
267    )]
268    OperationNotSupported { operation: String, reason: String },
269
270    /// Setup cannot put a resource where the chosen cluster could use it.
271    #[error(
272        code = "SETUP_PLACEMENT_UNSUPPORTED",
273        message = "{message}",
274        retryable = "false",
275        internal = "false",
276        http_status_code = 422
277    )]
278    SetupPlacementUnsupported {
279        /// What to change, in plain words.
280        message: String,
281        /// Type of the resource that cannot be placed.
282        resource_type: String,
283        /// Id of the resource that cannot be placed.
284        resource_id: String,
285    },
286
287    /// Local filesystem error.
288    #[error(
289        code = "LOCAL_FILESYSTEM_ERROR",
290        message = "Local filesystem error for '{path}' during {operation}",
291        retryable = "false",
292        internal = "false"
293    )]
294    LocalFilesystemError { path: String, operation: String },
295
296    /// Feature not enabled.
297    #[error(
298        code = "FEATURE_NOT_ENABLED",
299        message = "Feature '{feature}' is not enabled",
300        retryable = "false",
301        internal = "false"
302    )]
303    FeatureNotEnabled { feature: String },
304
305    /// A resource requires setup capabilities unavailable to automatic management.
306    #[error(
307        code = "AUTOMATIC_SETUP_RESOURCE_UNSUPPORTED",
308        message = "Automatic infrastructure management does not support {resource_type} '{resource_id}' on {platform}; use manual setup",
309        retryable = "false",
310        internal = "false",
311        http_status_code = 400
312    )]
313    AutomaticSetupResourceUnsupported {
314        resource_type: String,
315        resource_id: String,
316        platform: Platform,
317    },
318
319    /// A sandbox capability is unavailable on the target platform.
320    #[error(
321        code = "SANDBOX_CAPABILITY_UNSUPPORTED",
322        message = "Sandbox capability '{capability}' is not supported on {platform}",
323        retryable = "false",
324        internal = "false",
325        http_status_code = 400
326    )]
327    SandboxCapabilityUnsupported {
328        /// The capability that was requested
329        capability: String,
330        /// The platform that does not offer it
331        platform: String,
332    },
333
334    /// The target platform has no sandbox backend at all.
335    #[error(
336        code = "SANDBOX_PLATFORM_UNSUPPORTED",
337        message = "Sandbox is not available on {platform}",
338        retryable = "false",
339        internal = "false",
340        http_status_code = 400
341    )]
342    SandboxPlatformUnsupported {
343        /// The platform with no sandbox backend
344        platform: String,
345    },
346
347    /// A bundle signature or signing key was rejected.
348    #[error(
349        code = "BUNDLE_SIGNATURE_INVALID",
350        message = "Bundle signature invalid: {reason}",
351        retryable = "false",
352        internal = "false",
353        http_status_code = 400
354    )]
355    BundleSignatureInvalid {
356        /// Why the signature or key was rejected
357        reason: String,
358    },
359
360    /// A release signing key was rejected.
361    #[error(
362        code = "RELEASE_SIGNING_KEY_INVALID",
363        message = "Release signing key invalid: {reason}",
364        retryable = "false",
365        internal = "false",
366        http_status_code = 400
367    )]
368    ReleaseSigningKeyInvalid {
369        /// Why the key was rejected
370        reason: String,
371    },
372
373    /// The stack's signing setting can't become the install's signing settings.
374    #[error(
375        code = "SIGNING_SETTINGS_INVALID",
376        message = "Signing settings invalid: {reason}",
377        retryable = "false",
378        internal = "false",
379        http_status_code = 400
380    )]
381    SigningSettingsInvalid {
382        /// Why the settings were refused
383        reason: String,
384    },
385
386    /// A release statement could not be built or signed.
387    #[error(
388        code = "RELEASE_STATEMENT_INVALID",
389        message = "Release statement invalid: {reason}",
390        retryable = "false",
391        internal = "false",
392        http_status_code = 400
393    )]
394    ReleaseStatementInvalid {
395        /// Why the statement could not be built
396        reason: String,
397    },
398
399    /// A sandbox capability was refused.
400    #[error(
401        code = "SANDBOX_CAPABILITY_REFUSED",
402        message = "Sandbox capability refused: {reason}",
403        retryable = "false",
404        internal = "false",
405        http_status_code = 403
406    )]
407    SandboxCapabilityRefused {
408        /// Why it was refused. Deliberately coarse — it must not reveal which sandboxes exist.
409        reason: String,
410    },
411
412    /// A sandbox limit is missing or not a valid quantity.
413    #[error(
414        code = "SANDBOX_LIMIT_INVALID",
415        message = "Sandbox '{resource_id}' has an invalid {field} limit '{value}': {reason}",
416        retryable = "false",
417        internal = "false",
418        http_status_code = 400
419    )]
420    SandboxLimitInvalid {
421        /// The sandbox whose limit failed validation
422        resource_id: String,
423        /// Which limit (cpu, memory, disk, maxProcesses)
424        field: String,
425        /// The rejected value
426        value: String,
427        /// Why it was rejected
428        reason: String,
429    },
430
431    // Commands protocol errors
432    /// Invalid Commands envelope.
433    #[error(
434        code = "INVALID_ENVELOPE",
435        message = "Invalid Commands envelope: {message}",
436        retryable = "false",
437        internal = "false"
438    )]
439    InvalidEnvelope {
440        message: String,
441        field: Option<String>,
442    },
443
444    /// A command-enabled resource exists but the deployment has no token to
445    /// authenticate its command transport.
446    #[error(
447        code = "COMMAND_TOKEN_MISSING",
448        message = "Deployment has command-enabled resource '{resource_id}' but no deployment token to authenticate it: {reason}",
449        retryable = "false",
450        internal = "false"
451    )]
452    CommandTokenMissing { resource_id: String, reason: String },
453
454    /// Public URL configuration is invalid.
455    #[error(
456        code = "PUBLIC_URL_INVALID",
457        message = "Invalid public URL for resource '{resource_id}': {reason}",
458        retryable = "false",
459        internal = "false",
460        http_status_code = 400
461    )]
462    PublicUrlInvalid { resource_id: String, reason: String },
463
464    /// JSON serialization failed.
465    #[error(
466        code = "JSON_SERIALIZATION_FAILED",
467        message = "Failed to serialize JSON: {reason}",
468        retryable = "false",
469        internal = "false"
470    )]
471    JsonSerializationFailed { reason: String },
472
473    /// JSON deserialization failed.
474    #[error(
475        code = "JSON_DESERIALIZATION_FAILED",
476        message = "Failed to deserialize JSON: {reason}",
477        retryable = "false",
478        internal = "false"
479    )]
480    JsonDeserializationFailed { reason: String },
481
482    /// Distribution template serialization failed.
483    #[error(
484        code = "TEMPLATE_SERIALIZATION_FAILED",
485        message = "Failed to serialize {format} template: {reason}",
486        retryable = "false",
487        internal = "true"
488    )]
489    TemplateSerializationFailed { format: String, reason: String },
490
491    /// A management ExternalId is not 32 to 128 ASCII letters and digits.
492    #[error(
493        code = "MANAGEMENT_EXTERNAL_ID_INVALID",
494        message = "Management ExternalId must be 32 to 128 ASCII letters and digits (got {length} characters)",
495        retryable = "false",
496        internal = "false",
497        http_status_code = 400
498    )]
499    ManagementExternalIdInvalid {
500        /// Length of the rejected value. The value itself is never echoed.
501        length: usize,
502    },
503
504    /// A role ARN a setup template is told to accept as its managing role is
505    /// not an IAM role ARN.
506    #[error(
507        code = "MANAGING_ROLE_ARN_INVALID",
508        message = "Managing role ARN '{arn}' is not an IAM role ARN (arn:<partition>:iam::<account>:role/<name>)",
509        retryable = "false",
510        internal = "false",
511        http_status_code = 400
512    )]
513    ManagingRoleArnInvalid {
514        /// The rejected ARN.
515        arn: String,
516    },
517
518    /// ImportData did not match the registered typed payload.
519    #[error(
520        code = "IMPORT_DATA_INVALID",
521        message = "Invalid ImportData for resource '{resource_id}' ({resource_type}) on {platform}",
522        retryable = "false",
523        internal = "false",
524        http_status_code = 400
525    )]
526    ImportDataInvalid {
527        resource_id: String,
528        resource_type: ResourceType,
529        platform: Platform,
530    },
531
532    /// No registry implementation exists for a resource/platform pair.
533    #[error(
534        code = "IMPORT_REGISTRATION_MISSING",
535        message = "Missing {registration_kind} registration for resource type '{resource_type}' on {platform}",
536        retryable = "false",
537        internal = "true"
538    )]
539    ImportRegistrationMissing {
540        resource_type: ResourceType,
541        platform: Platform,
542        registration_kind: String,
543    },
544
545    /// ImportData schema serialization failed.
546    #[error(
547        code = "IMPORT_SCHEMA_SERIALIZATION_FAILED",
548        message = "Failed to serialize ImportData schema",
549        retryable = "false",
550        internal = "true"
551    )]
552    ImportSchemaSerializationFailed,
553}
554
555pub type Result<T> = alien_error::Result<T, ErrorData>;