use std::fmt;
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum ArchiveError {
NotAnArchive,
Version {
found: String,
expected: String,
},
UnexpectedEnd,
Invalid(String),
TooDeep,
Unsupported(String),
}
impl ArchiveError {
pub fn invalid(what: impl Into<String>) -> Self {
Self::Invalid(what.into())
}
pub fn unsupported(what: impl Into<String>) -> Self {
Self::Unsupported(what.into())
}
}
impl fmt::Display for ArchiveError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::NotAnArchive => f.write_str("not a pltrs archive"),
Self::Version { found, expected } => write!(
f,
"the archive was written by pltrs {found}, which this pltrs {expected} cannot read"
),
Self::UnexpectedEnd => f.write_str("the archive ends unexpectedly"),
Self::Invalid(what) => write!(f, "malformed archive: {what}"),
Self::TooDeep => f.write_str("the archive nests values too deeply"),
Self::Unsupported(what) => write!(f, "cannot archive {what}"),
}
}
}
impl std::error::Error for ArchiveError {}