1use std::fmt;
2use std::path::PathBuf;
3
4#[derive(Debug)]
6pub enum Error {
7 Io(PathBuf, std::io::Error),
9 Format(String),
11 Mismatch(Vec<String>),
14}
15
16impl Error {
17 pub(crate) fn format(msg: impl Into<String>) -> Self {
18 Self::Format(msg.into())
19 }
20}
21
22impl fmt::Display for Error {
23 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
24 match self {
25 Self::Io(path, e) => write!(f, "{}: {e}", path.display()),
26 Self::Format(msg) => f.write_str(msg),
27 Self::Mismatch(problems) => {
28 write!(f, "checkpoint does not match its config ({} problems)", problems.len())?;
29 for p in problems {
30 write!(f, "\n {p}")?;
31 }
32 Ok(())
33 }
34 }
35 }
36}
37
38impl std::error::Error for Error {}
39
40pub(crate) type Result<T> = std::result::Result<T, Error>;