use core::fmt;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Error {
HeaderTooShort,
HeaderLengthOutOfBounds,
HeaderNotUtf8,
InvalidHeader(&'static str),
UnsupportedDtype,
DataOffsetsOutOfBounds,
TensorNotFound,
DtypeMismatch,
Alignment,
UnevenLength,
ShapeDataMismatch,
InvalidTokenizer(&'static str),
InvalidInput(&'static str),
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::HeaderTooShort => write!(f, "safetensors header is too short"),
Self::HeaderLengthOutOfBounds => write!(f, "header length exceeds buffer size"),
Self::HeaderNotUtf8 => write!(f, "header is not valid UTF-8"),
Self::InvalidHeader(s) => write!(f, "invalid safetensors header: {}", s),
Self::UnsupportedDtype => write!(f, "unsupported tensor dtype"),
Self::DataOffsetsOutOfBounds => write!(f, "tensor data offsets are out of bounds"),
Self::TensorNotFound => write!(f, "tensor not found in model file"),
Self::DtypeMismatch => write!(f, "tensor dtype does not match the requested type"),
Self::Alignment => write!(f, "tensor data is not aligned for the requested type"),
Self::UnevenLength => write!(f, "tensor byte length is not a multiple of element size"),
Self::ShapeDataMismatch => write!(f, "declared shape does not match data length"),
Self::InvalidTokenizer(s) => write!(f, "invalid tokenizer: {}", s),
Self::InvalidInput(s) => write!(f, "invalid input: {}", s),
}
}
}
impl std::error::Error for Error {}
pub type Result<T> = core::result::Result<T, Error>;