use std::path::PathBuf;
#[derive(Debug, Clone, PartialEq)]
pub enum StorageError {
DirectoryNotFound(PathBuf),
DirectoryAlreadyExists(PathBuf),
Io { path: PathBuf, reason: String },
}
impl StorageError {
pub(crate) fn io(path: impl Into<PathBuf>, e: std::io::Error) -> Self {
StorageError::Io {
path: path.into(),
reason: e.to_string(),
}
}
}
impl std::fmt::Display for StorageError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
StorageError::DirectoryNotFound(p) => {
write!(f, "directory not found: {}", p.display())
}
StorageError::DirectoryAlreadyExists(p) => {
write!(f, "directory already exists: {}", p.display())
}
StorageError::Io { path, reason } => {
write!(f, "I/O error at {}: {}", path.display(), reason)
}
}
}
}
impl std::error::Error for StorageError {}