Skip to main content

alien_client_core/
error.rs

1use alien_error::AlienErrorData;
2use serde::{Deserialize, Serialize};
3
4/// Represents common infrastructure errors across multiple cloud platforms.
5#[derive(Debug, Clone, AlienErrorData, Serialize, Deserialize)]
6#[serde(rename_all = "camelCase")]
7pub enum ErrorData {
8    /// Invalid or malformed platform configuration.
9    #[error(
10        code = "INVALID_client_config",
11        message = "Invalid platform configuration: {message}",
12        retryable = "false",
13        internal = "false"
14    )]
15    InvalidClientConfig {
16        /// Human-readable description of the configuration issue
17        message: String,
18        /// Additional error details if available
19        errors: Option<String>,
20    },
21
22    /// Authentication with cloud provider failed.
23    #[error(
24        code = "AUTHENTICATION_ERROR",
25        message = "Authentication failed: {message}",
26        retryable = "true",
27        internal = "false"
28    )]
29    AuthenticationError {
30        /// Human-readable description of the authentication failure
31        message: String,
32    },
33
34    /// The requested resource does not exist.
35    #[error(
36        code = "REMOTE_RESOURCE_NOT_FOUND",
37        message = "{resource_type} '{resource_name}' not found",
38        retryable = "true",
39        internal = "false",
40        http_status_code = 404
41    )]
42    RemoteResourceNotFound {
43        /// Type of the resource that was not found
44        resource_type: String,
45        /// Name of the resource that was not found
46        resource_name: String,
47    },
48
49    /// Operation conflicts with current resource state (e.g., resource already exists, concurrent modifications, etag mismatch).
50    #[error(
51        code = "REMOTE_RESOURCE_CONFLICT",
52        message = "Conflict with {resource_type} '{resource_name}': {message}",
53        retryable = "true",
54        internal = "false"
55    )]
56    RemoteResourceConflict {
57        /// Type of the resource that has a conflict
58        resource_type: String,
59        /// Name of the resource that has a conflict
60        resource_name: String,
61        /// Human-readable description of the specific conflict
62        message: String,
63    },
64
65    /// Access denied due to insufficient permissions.
66    #[error(
67        code = "REMOTE_ACCESS_DENIED",
68        message = "Access denied to {resource_type} '{resource_name}'",
69        retryable = "true",
70        internal = "false"
71    )]
72    RemoteAccessDenied {
73        /// Type of the resource access was denied to
74        resource_type: String,
75        /// Name of the resource access was denied to
76        resource_name: String,
77    },
78
79    /// Request rate limit exceeded.
80    #[error(
81        code = "RATE_LIMIT_EXCEEDED",
82        message = "Rate limit exceeded: {message}",
83        retryable = "true",
84        internal = "false"
85    )]
86    RateLimitExceeded {
87        /// Human-readable description of the rate limit context
88        message: String,
89    },
90
91    /// Operation exceeded the allowed timeout.
92    #[error(
93        code = "TIMEOUT",
94        message = "Operation timed out: {message}",
95        retryable = "true",
96        internal = "false"
97    )]
98    Timeout {
99        /// Human-readable description of what operation timed out
100        message: String,
101    },
102
103    /// Service is temporarily unavailable.
104    #[error(
105        code = "REMOTE_SERVICE_UNAVAILABLE",
106        message = "Service unavailable: {message}",
107        retryable = "true",
108        internal = "false"
109    )]
110    RemoteServiceUnavailable {
111        /// Human-readable description of the service unavailability
112        message: String,
113    },
114
115    /// Quota or resource limits have been exceeded.
116    #[error(
117        code = "QUOTA_EXCEEDED",
118        message = "Quota exceeded: {message}",
119        retryable = "true",
120        internal = "false"
121    )]
122    QuotaExceeded {
123        /// Human-readable description of what quota was exceeded
124        message: String,
125    },
126
127    /// Network or request-level failure when sending HTTP request.
128    #[error(
129        code = "HTTP_REQUEST_FAILED",
130        message = "{message}",
131        retryable = "true",
132        internal = "false"
133    )]
134    HttpRequestFailed {
135        /// Human-readable description of the HTTP request failure
136        message: String,
137    },
138
139    /// Body cleanup failed after the service accepted the request.
140    #[error(
141        code = "HTTP_RESPONSE_BODY_READ_FAILED",
142        message = "HTTP {http_status} succeeded, but its response body could not be read",
143        retryable = "false",
144        internal = "false",
145        hint = "The request was already accepted. Check the remote state before retrying."
146    )]
147    HttpResponseBodyReadFailed {
148        /// Successful HTTP status received before the body read failed.
149        http_status: u16,
150    },
151
152    /// HTTP request succeeded but returned a non-success status code.
153    #[error(
154        code = "HTTP_RESPONSE_ERROR",
155        message = "{message}",
156        retryable = "true",
157        internal = "true"
158    )]
159    HttpResponseError {
160        /// Human-readable description of the HTTP response error
161        message: String,
162        /// The URL that returned the error
163        url: String,
164        /// HTTP status code returned
165        http_status: u16,
166        // Request body text
167        http_request_text: Option<String>,
168        /// Response body text if available
169        http_response_text: Option<String>,
170    },
171
172    /// The cloud service rejected the request and returned its own error code and message.
173    ///
174    /// Unlike [`ErrorData::HttpResponseError`], this is safe to show to users: it holds only the
175    /// service's code and message, never the request body or the raw response. Wrap the internal
176    /// `HttpResponseError` with it so those stay available for debugging. Retryability comes from
177    /// that source, because some rejections are transient (for example, an S3 bucket notification
178    /// whose target permission has not propagated yet). Only use it for a service whose error
179    /// messages don't echo submitted values; some APIs repeat request fields, including secrets.
180    #[error(
181        code = "REMOTE_REQUEST_REJECTED",
182        message = "{service} rejected the request ({provider_code}): {message}",
183        retryable = "inherit",
184        internal = "false"
185    )]
186    RemoteRequestRejected {
187        /// Cloud service that rejected the request (e.g. "S3")
188        service: String,
189        /// HTTP status code the service returned
190        http_status: u16,
191        /// The service's error code (e.g. "InvalidArgument")
192        provider_code: String,
193        /// The service's error message
194        message: String,
195    },
196
197    /// Failure during signing of an HTTP request (e.g., AWS SigV4).
198    #[error(
199        code = "REQUEST_SIGN_ERROR",
200        message = "Request signing failed: {message}",
201        retryable = "true",
202        internal = "true"
203    )]
204    RequestSignError {
205        /// Human-readable description of the signing failure
206        message: String,
207    },
208
209    /// Catch-all error
210    #[error(
211        code = "GENERIC_ERROR",
212        message = "{message}",
213        retryable = "true",
214        internal = "true"
215    )]
216    GenericError {
217        /// Human-readable description of the error
218        message: String,
219    },
220
221    /// Invalid or malformed input parameters provided to the operation.
222    #[error(
223        code = "INVALID_INPUT",
224        message = "Invalid input: {message}",
225        retryable = "false",
226        internal = "false"
227    )]
228    InvalidInput {
229        /// Human-readable description of what input was invalid
230        message: String,
231        /// Optional field name that was invalid
232        field_name: Option<String>,
233    },
234
235    /// Failed to serialize or deserialize data.
236    #[error(
237        code = "SERIALIZATION_ERROR",
238        message = "Serialization failed: {message}",
239        retryable = "false",
240        internal = "true"
241    )]
242    SerializationError {
243        /// Human-readable description of the serialization failure
244        message: String,
245    },
246
247    /// Failed to load or parse kubeconfig file.
248    #[error(
249        code = "KUBECONFIG_ERROR",
250        message = "Kubeconfig error: {message}",
251        retryable = "false",
252        internal = "false"
253    )]
254    KubeconfigError {
255        /// Human-readable description of the kubeconfig error
256        message: String,
257    },
258
259    /// Failed to load data from base64 or file.
260    #[error(
261        code = "DATA_LOAD_ERROR",
262        message = "Failed to load data: {message}",
263        retryable = "false",
264        internal = "false"
265    )]
266    DataLoadError {
267        /// Human-readable description of the data loading failure
268        message: String,
269    },
270}
271
272/// Convenient alias with default error type `ErrorData`. Allows callers to override the
273/// error type when needed while still accepting the common single-generic form `Result<T>`.
274pub type Result<T, E = ErrorData> = alien_error::Result<T, E>;
275
276/// Convenience alias representing a constructed AlienError with our `ErrorData` payload.
277pub type Error = alien_error::AlienError<ErrorData>;