Skip to main content

alien_commands_client/
error.rs

1/// Errors that can occur when invoking commands.
2#[derive(Debug, thiserror::Error)]
3pub enum CommandError {
4    /// Command creation failed (HTTP error from manager)
5    #[error("command creation failed (HTTP {status}): {body}")]
6    CreationFailed { status: u16, body: String },
7
8    /// Command timed out waiting for result
9    #[error("command {command_id} timed out (last state: {last_state})")]
10    Timeout {
11        command_id: String,
12        last_state: String,
13    },
14
15    /// Deployment returned an error
16    #[error("command {command_id} failed: [{code}] {message}")]
17    DeploymentError {
18        command_id: String,
19        code: String,
20        message: String,
21    },
22
23    /// Command expired (deadline passed)
24    #[error("command {command_id} expired")]
25    Expired { command_id: String },
26
27    /// Failed to decode response
28    #[error("failed to decode response for command {command_id}: {reason}")]
29    ResponseDecodingFailed { command_id: String, reason: String },
30
31    /// Storage download failed (for large responses)
32    #[error("storage operation failed: {reason}")]
33    StorageOperationFailed { reason: String },
34
35    /// HTTP/network error
36    #[error("HTTP error: {0}")]
37    HttpError(#[from] reqwest::Error),
38
39    /// JSON serialization/deserialization error
40    #[error("JSON error: {0}")]
41    JsonError(#[from] serde_json::Error),
42}
43
44impl CommandError {
45    /// Returns true if this error is potentially retryable.
46    pub fn is_retryable(&self) -> bool {
47        matches!(
48            self,
49            CommandError::Timeout { .. }
50                | CommandError::HttpError(_)
51                | CommandError::StorageOperationFailed { .. }
52        )
53    }
54}