use std::error::Error;
use std::fmt;
use std::path::PathBuf;
#[derive(Debug)]
pub enum ManifestError {
Read {
path: PathBuf,
source: std::io::Error,
},
Deserialize {
path: PathBuf,
source: toml::de::Error,
},
InvalidField {
path: PathBuf,
field: String,
reason: String,
},
}
impl fmt::Display for ManifestError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Read { path, source } => {
write!(f, "failed to read manifest {}: {source}", path.display())
}
Self::Deserialize { path, source } => {
write!(f, "failed to parse manifest {}: {source}", path.display())
}
Self::InvalidField {
path,
field,
reason,
} => write!(
f,
"invalid `{field}` in manifest {}: {reason}",
path.display()
),
}
}
}
impl Error for ManifestError {
fn source(&self) -> Option<&(dyn Error + 'static)> {
match self {
Self::Read { source, .. } => Some(source),
Self::Deserialize { source, .. } => Some(source),
Self::InvalidField { .. } => None,
}
}
}