use std::io;
use ndarray::ShapeError;
use reductive::error::ReductiveError;
use thiserror::Error;
pub type Result<T> = ::std::result::Result<T, Error>;
#[non_exhaustive]
#[derive(Debug, Error)]
pub enum Error {
#[error("{context}")]
Context {
context: String,
#[source]
error: Box<Error>,
},
#[error("Invalid file format {0}")]
Format(String),
#[error("{0}")]
NGramConversion(String),
#[error("Cannot construct matrix with the given shape")]
MatrixShape(#[source] ShapeError),
#[error("{desc}")]
Read {
desc: String,
#[source]
error: io::Error,
},
#[error("Unknown chunk identifier {0}")]
UnknownChunkIdentifier(u32),
#[error("Data cannot be represented using native word size")]
Overflow,
#[error("Can't convert {from} to {to}")]
Conversion { from: String, to: String },
#[error("Cannot quantize embeddings")]
Quantization(#[source] ReductiveError),
#[error("{desc}")]
Write {
desc: String,
#[source]
error: io::Error,
},
}
impl Error {
pub fn context(self, context: impl Into<String>) -> Self {
Error::Context {
context: context.into(),
error: self.into(),
}
}
pub fn ngram_conversion_error(desc: impl Into<String>) -> Self {
Error::NGramConversion(desc.into())
}
pub fn conversion_error(from: impl Into<String>, to: impl Into<String>) -> Self {
Error::Conversion {
from: from.into(),
to: to.into(),
}
}
pub fn read_error(desc: impl Into<String>, error: io::Error) -> Self {
Error::Read {
desc: desc.into(),
error,
}
}
pub fn write_error(desc: impl Into<String>, error: io::Error) -> Self {
Error::Write {
desc: desc.into(),
error,
}
}
}