use std::path::PathBuf;
use thiserror::Error;
use url::ParseError;
use validator::ValidationErrors;
#[derive(Error, Debug)]
pub enum FirecrackerError {
#[error("HTTP client error: {0}")]
HttpClient(#[from] reqwest::Error),
#[error("URL parse error: {0}")]
UrlParseError(#[from] ParseError),
#[error("Serialization error: {0}")]
Serialization(#[from] serde_json::Error),
#[error("Validation error: {0}")]
Validation(#[from] ValidationErrors),
#[error("Firecracker API error: {status_code} - {message}")]
Api { status_code: u16, message: String },
#[error("Invalid path: {0}")]
InvalidPath(String),
#[error("File system error for path {path}: {source}")]
FileSystem {
path: PathBuf,
source: std::io::Error,
},
#[error("Configuration error: {0}")]
Config(String),
#[error("Snapshot error: {0}")]
Snapshot(String),
#[error("Rate limit exceeded: {0}")]
RateLimit(String),
#[error("Invalid VM state: {current_state}. Expected one of: {expected_states:?}")]
InvalidState {
current_state: String,
expected_states: Vec<String>,
},
#[error("Operation timed out after {duration_secs} seconds")]
Timeout { duration_secs: u64 },
#[error("Internal error: {0}")]
Internal(String),
}
pub type FirecrackerResult<T> = Result<T, FirecrackerError>;