use std::fmt;
#[derive(Debug)]
#[non_exhaustive]
pub enum IndexError {
InvalidMagic {
found: [u8; 6],
},
UnsupportedVersion {
found: u32,
supported: u32,
},
Truncated {
section: &'static str,
},
Corrupt {
reason: &'static str,
},
Fst(fst::Error),
}
impl fmt::Display for IndexError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::InvalidMagic { found } => {
write!(f, "invalid magic: expected \"DSIDX1\", found {found:02x?}")
}
Self::UnsupportedVersion { found, supported } => {
write!(
f,
"index version {found} unsupported; this crate decodes up to {supported}"
)
}
Self::Truncated { section } => {
write!(f, "truncated index: ran out of bytes reading {section}")
}
Self::Corrupt { reason } => write!(f, "corrupt index: {reason}"),
Self::Fst(e) => write!(f, "term dictionary error: {e}"),
}
}
}
impl std::error::Error for IndexError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Self::Fst(e) => Some(e),
_ => None,
}
}
}
impl From<fst::Error> for IndexError {
fn from(e: fst::Error) -> Self {
Self::Fst(e)
}
}