use core::fmt;
pub type Result<T> = core::result::Result<T, Error>;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Error {
Io {
token: &'static str,
offset: u64,
},
BadSuperblock(SuperblockReason),
UnsupportedFeature(&'static str),
UnsupportedProfile(&'static str),
UnsupportedChecksum(&'static str),
CsumMismatch {
logical: u64,
},
CorruptBtree {
token: &'static str,
logical: u64,
},
NotFound,
NotARegularFile,
NotASymlink,
BadCompression {
algorithm: &'static str,
},
OutOfMemory {
token: &'static str,
},
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SuperblockReason {
BadMagic,
BadCsum,
GenerationSkew,
NoValidCopy,
UnsupportedCsumType,
UnsupportedIncompat,
BadGeometry,
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Io { token, offset } => {
write!(f, "io error ({token}) at offset {offset}")
}
Self::BadSuperblock(reason) => write!(f, "bad superblock: {reason:?}"),
Self::UnsupportedFeature(t) => write!(f, "unsupported feature: {t}"),
Self::UnsupportedProfile(t) => write!(f, "unsupported chunk profile: {t}"),
Self::UnsupportedChecksum(t) => write!(f, "unsupported checksum type: {t}"),
Self::CsumMismatch { logical } => {
write!(f, "metadata csum mismatch at logical {logical:#x}")
}
Self::CorruptBtree { token, logical } => {
write!(f, "corrupt b-tree ({token}) at logical {logical:#x}")
}
Self::NotFound => write!(f, "path component not found"),
Self::NotARegularFile => write!(f, "path does not resolve to a regular file"),
Self::NotASymlink => write!(f, "path does not resolve to a symlink"),
Self::BadCompression { algorithm } => write!(f, "bad compressed extent ({algorithm})"),
Self::OutOfMemory { token } => write!(f, "out of memory ({token})"),
}
}
}
#[cfg(feature = "std")]
impl std::error::Error for Error {}