firecracker_http_client/
error.rs

1use std::path::PathBuf;
2use thiserror::Error;
3use url::ParseError;
4use validator::ValidationErrors;
5
6/// Represents all possible errors that can occur when using the Firecracker client.
7#[derive(Error, Debug)]
8pub enum FirecrackerError {
9    /// Error occurred during HTTP client operations
10    #[error("HTTP client error: {0}")]
11    HttpClient(#[from] reqwest::Error),
12
13    /// Error parsing URLs
14    #[error("URL parse error: {0}")]
15    UrlParseError(#[from] ParseError),
16
17    /// Error during serialization/deserialization
18    #[error("Serialization error: {0}")]
19    Serialization(#[from] serde_json::Error),
20
21    /// Error validating input
22    #[error("Validation error: {0}")]
23    Validation(#[from] ValidationErrors),
24
25    /// Error from Firecracker API
26    #[error("Firecracker API error: {status_code} - {message}")]
27    Api { status_code: u16, message: String },
28
29    /// Error with invalid paths
30    #[error("Invalid path: {0}")]
31    InvalidPath(String),
32
33    /// Error accessing files or paths
34    #[error("File system error for path {path}: {source}")]
35    FileSystem {
36        path: PathBuf,
37        source: std::io::Error,
38    },
39
40    /// Configuration error
41    #[error("Configuration error: {0}")]
42    Config(String),
43
44    /// Error during snapshot operations
45    #[error("Snapshot error: {0}")]
46    Snapshot(String),
47
48    /// Error with rate limiting
49    #[error("Rate limit exceeded: {0}")]
50    RateLimit(String),
51
52    /// Error with VM state
53    #[error("Invalid VM state: {current_state}. Expected one of: {expected_states:?}")]
54    InvalidState {
55        current_state: String,
56        expected_states: Vec<String>,
57    },
58
59    /// Timeout error
60    #[error("Operation timed out after {duration_secs} seconds")]
61    Timeout { duration_secs: u64 },
62
63    /// Generic error for cases that don't fit other categories
64    #[error("Internal error: {0}")]
65    Internal(String),
66}
67
68/// Result type for Firecracker operations
69pub type FirecrackerResult<T> = Result<T, FirecrackerError>;