use arcbox_error::CommonError;
use thiserror::Error;
pub type Result<T> = std::result::Result<T, CoreError>;
#[derive(Debug, Error)]
pub enum CoreError {
#[error(transparent)]
Common(#[from] CommonError),
#[error("VMM error: {0}")]
Vmm(#[from] arcbox_vmm::VmmError),
#[error("snapshot error: {0}")]
Snapshot(#[from] arcbox_vmm::SnapshotError),
#[error("VM error: {0}")]
Vm(String),
#[error("machine error: {0}")]
Machine(String),
#[error("persistence error: {0}")]
Persistence(#[from] toml::de::Error),
#[error("internal lock poisoned")]
LockPoisoned,
#[error("filesystem error: {0}")]
Fs(#[from] arcbox_fs::FsError),
#[error("network error: {0}")]
Net(#[from] arcbox_net::NetError),
}
impl CoreError {
#[must_use]
pub fn config(msg: impl Into<String>) -> Self {
Self::Common(CommonError::config(msg))
}
#[must_use]
pub fn not_found(resource: impl Into<String>) -> Self {
Self::Common(CommonError::not_found(resource))
}
#[must_use]
pub fn already_exists(resource: impl Into<String>) -> Self {
Self::Common(CommonError::already_exists(resource))
}
#[must_use]
pub fn invalid_state(msg: impl Into<String>) -> Self {
Self::Common(CommonError::invalid_state(msg))
}
}
impl From<std::io::Error> for CoreError {
fn from(err: std::io::Error) -> Self {
Self::Common(CommonError::from(err))
}
}