Skip to main content

herolib_virt/cloudhv/
errors.rs

1use std::io;
2use thiserror::Error;
3
4#[derive(Error, Debug)]
5pub enum CloudHypervisorError {
6    #[error("IO error: {0}")]
7    Io(#[from] io::Error),
8
9    #[error("API error: {0}")]
10    Api(String),
11
12    #[error("Process error: {0}")]
13    Process(String),
14
15    #[error("Configuration error: {0}")]
16    Config(String),
17
18    #[error("VM not found: {0}")]
19    VmNotFound(String),
20
21    #[error("VM already exists: {0}")]
22    VmAlreadyExists(String),
23
24    #[error("Invalid state: {0}")]
25    InvalidState(String),
26
27    #[error("Device error: {0}")]
28    Device(String),
29
30    #[error("Snapshot error: {0}")]
31    Snapshot(String),
32
33    #[error("Script error: {0}")]
34    Script(String),
35
36    #[error("HTTP request failed: {0}")]
37    Http(String),
38
39    #[error("Hyper error: {0}")]
40    Hyper(String),
41
42    #[error("Which error: {0}")]
43    Which(String),
44
45    #[error("JSON error: {0}")]
46    Json(#[from] serde_json::Error),
47
48    #[error("Timeout error: {0}")]
49    Timeout(String),
50
51    #[error("Resource error: {0}")]
52    Resource(String),
53
54    #[error("Validation error: {0}")]
55    Validation(String),
56
57    #[error("Feature not supported: {feature} - {reason}")]
58    NotSupported { feature: String, reason: String },
59}
60
61// Implement From for hyper::Error
62impl From<hyper::Error> for CloudHypervisorError {
63    fn from(err: hyper::Error) -> Self {
64        CloudHypervisorError::Hyper(err.to_string())
65    }
66}
67
68// Implement From for which::Error  
69impl From<which::Error> for CloudHypervisorError {
70    fn from(err: which::Error) -> Self {
71        CloudHypervisorError::Which(err.to_string())
72    }
73}
74
75pub type Result<T> = std::result::Result<T, CloudHypervisorError>;