use std::fmt;
#[derive(Debug, Clone)]
pub enum VZError {
NotSupported,
InvalidConfiguration(String),
OperationFailed(String),
InvalidState {
expected: String,
actual: String,
},
ConnectionFailed(String),
Timeout(String),
NotFound(String),
Internal {
code: i32,
message: String,
},
}
impl fmt::Display for VZError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::NotSupported => write!(f, "Virtualization not supported on this system"),
Self::InvalidConfiguration(msg) => write!(f, "Invalid configuration: {msg}"),
Self::OperationFailed(msg) => write!(f, "VM operation failed: {msg}"),
Self::InvalidState { expected, actual } => {
write!(f, "Invalid state: expected {expected}, got {actual}")
}
Self::ConnectionFailed(msg) => write!(f, "Connection failed: {msg}"),
Self::Timeout(msg) => write!(f, "Timeout: {msg}"),
Self::NotFound(path) => write!(f, "Not found: {path}"),
Self::Internal { code, message } => {
write!(f, "Internal error (code={code}): {message}")
}
}
}
}
impl std::error::Error for VZError {}
pub type VZResult<T> = Result<T, VZError>;