arcbox_hypervisor/
error.rs1use arcbox_error::CommonError;
4use thiserror::Error;
5
6pub type Result<T> = std::result::Result<T, HypervisorError>;
8
9#[derive(Debug, Error)]
11pub enum HypervisorError {
12 #[error(transparent)]
14 Common(#[from] CommonError),
15
16 #[error("platform not supported: {0}")]
18 UnsupportedPlatform(String),
19
20 #[error("failed to initialize hypervisor: {0}")]
22 InitializationFailed(String),
23
24 #[error("failed to create VM: {0}")]
26 VmCreationFailed(String),
27
28 #[error("failed to create vCPU {id}: {reason}")]
30 VcpuCreationFailed { id: u32, reason: String },
31
32 #[error("memory error: {0}")]
34 MemoryError(String),
35
36 #[error("VM state error: expected {expected}, got {actual}")]
38 VmStateError { expected: String, actual: String },
39
40 #[error("vCPU execution error: {0}")]
42 VcpuRunError(String),
43
44 #[error("device error: {0}")]
46 DeviceError(String),
47
48 #[error("VM error: {0}")]
50 VmError(String),
51
52 #[error("snapshot error: {0}")]
54 SnapshotError(String),
55
56 #[error("not supported: {0}")]
58 NotSupported(String),
59
60 #[cfg(target_os = "macos")]
62 #[error("darwin error: {0}")]
63 DarwinError(String),
64
65 #[cfg(target_os = "linux")]
67 #[error("KVM error: {0}")]
68 KvmError(String),
69}
70
71impl HypervisorError {
72 #[must_use]
74 pub fn timeout(msg: impl Into<String>) -> Self {
75 Self::Common(CommonError::timeout(msg))
76 }
77
78 #[must_use]
80 pub fn invalid_config(msg: impl Into<String>) -> Self {
81 Self::Common(CommonError::config(msg))
82 }
83}
84
85impl From<std::io::Error> for HypervisorError {
87 fn from(err: std::io::Error) -> Self {
88 Self::Common(CommonError::from(err))
89 }
90}