use arcbox_error::CommonError;
use thiserror::Error;
pub type Result<T> = std::result::Result<T, HypervisorError>;
#[derive(Debug, Error)]
pub enum HypervisorError {
#[error(transparent)]
Common(#[from] CommonError),
#[error("platform not supported: {0}")]
UnsupportedPlatform(String),
#[error("failed to initialize hypervisor: {0}")]
InitializationFailed(String),
#[error("failed to create VM: {0}")]
VmCreationFailed(String),
#[error("failed to create vCPU {id}: {reason}")]
VcpuCreationFailed { id: u32, reason: String },
#[error("memory error: {0}")]
MemoryError(String),
#[error("VM state error: expected {expected}, got {actual}")]
VmStateError { expected: String, actual: String },
#[error("vCPU execution error: {0}")]
VcpuRunError(String),
#[error("device error: {0}")]
DeviceError(String),
#[error("VM error: {0}")]
VmError(String),
#[error("snapshot error: {0}")]
SnapshotError(String),
#[error("not supported: {0}")]
NotSupported(String),
#[cfg(target_os = "macos")]
#[error("darwin error: {0}")]
DarwinError(String),
#[cfg(target_os = "linux")]
#[error("KVM error: {0}")]
KvmError(String),
}
impl HypervisorError {
#[must_use]
pub fn timeout(msg: impl Into<String>) -> Self {
Self::Common(CommonError::timeout(msg))
}
#[must_use]
pub fn invalid_config(msg: impl Into<String>) -> Self {
Self::Common(CommonError::config(msg))
}
}
impl From<std::io::Error> for HypervisorError {
fn from(err: std::io::Error) -> Self {
Self::Common(CommonError::from(err))
}
}