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 /// A remote asynchronous operation finished unsuccessfully; its handle cannot recover.
128 /// Retrying the issuing handler can reissue the operation, so preserve executor retries.
129 /// Callers that persist handles must recognize this variant and stop polling the old handle.
130 #[error(
131 code = "REMOTE_OPERATION_FAILED",
132 message = "{operation} for '{resource_name}' finished with status {status}: {message}",
133 retryable = "true",
134 internal = "true"
135 )]
136 RemoteOperationFailed {
137 /// Operation that finished unsuccessfully.
138 operation: String,
139 /// Resource associated with the operation.
140 resource_name: String,
141 /// Terminal status reported by the provider.
142 status: String,
143 /// Provider error code, when supplied.
144 provider_code: Option<String>,
145 /// Provider diagnostics, including its message and any nested error details.
146 message: String,
147 },
148
149 /// Network or request-level failure when sending HTTP request.
150 #[error(
151 code = "HTTP_REQUEST_FAILED",
152 message = "{message}",
153 retryable = "true",
154 internal = "false"
155 )]
156 HttpRequestFailed {
157 /// Human-readable description of the HTTP request failure
158 message: String,
159 },
160
161 /// Body cleanup failed after the service accepted the request.
162 #[error(
163 code = "HTTP_RESPONSE_BODY_READ_FAILED",
164 message = "HTTP {http_status} succeeded, but its response body could not be read",
165 retryable = "false",
166 internal = "false",
167 hint = "The request was already accepted. Check the remote state before retrying."
168 )]
169 HttpResponseBodyReadFailed {
170 /// Successful HTTP status received before the body read failed.
171 http_status: u16,
172 },
173
174 /// HTTP request succeeded but returned a non-success status code.
175 #[error(
176 code = "HTTP_RESPONSE_ERROR",
177 message = "{message}",
178 retryable = "true",
179 internal = "true"
180 )]
181 HttpResponseError {
182 /// Human-readable description of the HTTP response error
183 message: String,
184 /// The URL that returned the error
185 url: String,
186 /// HTTP status code returned
187 http_status: u16,
188 // Request body text
189 http_request_text: Option<String>,
190 /// Response body text if available
191 http_response_text: Option<String>,
192 },
193
194 /// The cloud service rejected the request and returned its own error code and message.
195 ///
196 /// Unlike [`ErrorData::HttpResponseError`], this is safe to show to users: it holds only the
197 /// service's code and message, never the request body or the raw response. Wrap the internal
198 /// `HttpResponseError` with it so those stay available for debugging. Retryability comes from
199 /// that source, because some rejections are transient (for example, an S3 bucket notification
200 /// whose target permission has not propagated yet). Only use it for a service whose error
201 /// messages don't echo submitted values; some APIs repeat request fields, including secrets.
202 #[error(
203 code = "REMOTE_REQUEST_REJECTED",
204 message = "{service} rejected the request ({provider_code}): {message}",
205 retryable = "inherit",
206 internal = "false"
207 )]
208 RemoteRequestRejected {
209 /// Cloud service that rejected the request (e.g. "S3")
210 service: String,
211 /// HTTP status code the service returned
212 http_status: u16,
213 /// The service's error code (e.g. "InvalidArgument")
214 provider_code: String,
215 /// The service's error message
216 message: String,
217 },
218
219 /// Failure during signing of an HTTP request (e.g., AWS SigV4).
220 #[error(
221 code = "REQUEST_SIGN_ERROR",
222 message = "Request signing failed: {message}",
223 retryable = "true",
224 internal = "true"
225 )]
226 RequestSignError {
227 /// Human-readable description of the signing failure
228 message: String,
229 },
230
231 /// Catch-all error
232 #[error(
233 code = "GENERIC_ERROR",
234 message = "{message}",
235 retryable = "true",
236 internal = "true"
237 )]
238 GenericError {
239 /// Human-readable description of the error
240 message: String,
241 },
242
243 /// Invalid or malformed input parameters provided to the operation.
244 #[error(
245 code = "INVALID_INPUT",
246 message = "Invalid input: {message}",
247 retryable = "false",
248 internal = "false"
249 )]
250 InvalidInput {
251 /// Human-readable description of what input was invalid
252 message: String,
253 /// Optional field name that was invalid
254 field_name: Option<String>,
255 },
256
257 /// Failed to serialize or deserialize data.
258 #[error(
259 code = "SERIALIZATION_ERROR",
260 message = "Serialization failed: {message}",
261 retryable = "false",
262 internal = "true"
263 )]
264 SerializationError {
265 /// Human-readable description of the serialization failure
266 message: String,
267 },
268
269 /// Failed to load or parse kubeconfig file.
270 #[error(
271 code = "KUBECONFIG_ERROR",
272 message = "Kubeconfig error: {message}",
273 retryable = "false",
274 internal = "false"
275 )]
276 KubeconfigError {
277 /// Human-readable description of the kubeconfig error
278 message: String,
279 },
280
281 /// Failed to load data from base64 or file.
282 #[error(
283 code = "DATA_LOAD_ERROR",
284 message = "Failed to load data: {message}",
285 retryable = "false",
286 internal = "false"
287 )]
288 DataLoadError {
289 /// Human-readable description of the data loading failure
290 message: String,
291 },
292}
293
294/// Convenient alias with default error type `ErrorData`. Allows callers to override the
295/// error type when needed while still accepting the common single-generic form `Result<T>`.
296pub type Result<T, E = ErrorData> = alien_error::Result<T, E>;
297
298/// Convenience alias representing a constructed AlienError with our `ErrorData` payload.
299pub type Error = alien_error::AlienError<ErrorData>;