use arcbox_error::CommonError;
use thiserror::Error;
pub type Result<T> = std::result::Result<T, ContainerError>;
#[derive(Debug, Error)]
pub enum ContainerError {
#[error(transparent)]
Common(#[from] CommonError),
#[error("image error: {0}")]
Image(String),
#[error("volume error: {0}")]
Volume(String),
#[error("runtime error: {0}")]
Runtime(String),
#[error("internal lock poisoned")]
LockPoisoned,
}
impl From<std::io::Error> for ContainerError {
fn from(err: std::io::Error) -> Self {
Self::Common(CommonError::from(err))
}
}
impl ContainerError {
#[must_use]
pub fn not_found(resource: impl Into<String>) -> Self {
Self::Common(CommonError::not_found(resource))
}
#[must_use]
pub fn invalid_state(msg: impl Into<String>) -> Self {
Self::Common(CommonError::invalid_state(msg))
}
#[must_use]
pub fn config(msg: impl Into<String>) -> Self {
Self::Common(CommonError::config(msg))
}
#[must_use]
pub fn already_exists(resource: impl Into<String>) -> Self {
Self::Common(CommonError::already_exists(resource))
}
#[must_use]
pub const fn is_not_found(&self) -> bool {
matches!(self, Self::Common(CommonError::NotFound(_)))
}
#[must_use]
pub const fn is_invalid_state(&self) -> bool {
matches!(self, Self::Common(CommonError::InvalidState(_)))
}
}