use std::fmt;
use std::path::PathBuf;
#[derive(Debug)]
pub enum Error {
Io(PathBuf, std::io::Error),
Format(String),
Mismatch(Vec<String>),
}
impl Error {
pub(crate) fn format(msg: impl Into<String>) -> Self {
Self::Format(msg.into())
}
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Io(path, e) => write!(f, "{}: {e}", path.display()),
Self::Format(msg) => f.write_str(msg),
Self::Mismatch(problems) => {
write!(f, "checkpoint does not match its config ({} problems)", problems.len())?;
for p in problems {
write!(f, "\n {p}")?;
}
Ok(())
}
}
}
}
impl std::error::Error for Error {}
pub(crate) type Result<T> = std::result::Result<T, Error>;