use std::error::Error;
use std::fmt::{Display, Formatter, Result as FResult};
use std::path::PathBuf;
#[derive(Debug)]
pub enum ContainerHashesError {
ReadError { path: PathBuf, err: std::io::Error },
ParseError { path: PathBuf, err: serde_yaml::Error },
DuplicateHash { path: PathBuf, hash: String },
SerializeError { err: serde_yaml::Error },
WriteError { path: PathBuf, err: std::io::Error },
}
impl Display for ContainerHashesError {
fn fmt(&self, f: &mut Formatter<'_>) -> FResult {
use ContainerHashesError::*;
match self {
ReadError { path, .. } => write!(f, "Failed to read hash file '{}'", path.display()),
ParseError { path, .. } => write!(f, "Failed to parse hash file '{}' as YAML", path.display()),
DuplicateHash { path, hash } => write!(f, "Hash file '{}' contains duplicate hash '{}'", path.display(), hash),
SerializeError { .. } => write!(f, "Failed to serialize hash file"),
WriteError { path, .. } => write!(f, "Failed to write hash file to '{}'", path.display()),
}
}
}
impl Error for ContainerHashesError {
fn source(&self) -> Option<&(dyn Error + 'static)> {
use ContainerHashesError::*;
match self {
ReadError { err, .. } => Some(err),
ParseError { err, .. } => Some(err),
DuplicateHash { .. } => None,
SerializeError { err, .. } => Some(err),
WriteError { err, .. } => Some(err),
}
}
}