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),
VectorsUnsupported,
VectorDim {
expected: u32,
found: u32,
},
}
impl fmt::Display for IndexError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::InvalidMagic { found } => {
write!(f, "invalid magic: expected \"DSIDX2\", 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}"),
Self::VectorsUnsupported => write!(
f,
"index carries a quantized-vector section; rebuild with the `vectors` feature to read it"
),
Self::VectorDim { expected, found } => {
write!(f, "vector dimension {found} does not match the index dimension {expected}")
}
}
}
}
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)
}
}