use arrow_schema::ArrowError;
#[derive(Debug)]
pub enum Error {
Arrow(String),
Schema(String),
IO(String),
Index(String),
}
pub type Result<T> = std::result::Result<T, Error>;
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let (catalog, message) = match self {
Self::Arrow(s) => ("Arrow", s),
Self::Schema(s) => ("Schema", s),
Self::IO(s) => ("I/O", s),
Self::Index(s) => ("Index", s),
};
write!(f, "LanceError({catalog}): {message}")
}
}
impl From<ArrowError> for Error {
fn from(e: ArrowError) -> Self {
Self::Arrow(e.to_string())
}
}
impl From<&ArrowError> for Error {
fn from(e: &ArrowError) -> Self {
Self::Arrow(e.to_string())
}
}
impl From<std::io::Error> for Error {
fn from(e: std::io::Error) -> Self {
Self::IO(e.to_string())
}
}
impl From<object_store::Error> for Error {
fn from(e: object_store::Error) -> Self {
Self::IO(e.to_string())
}
}
impl From<prost::DecodeError> for Error {
fn from(e: prost::DecodeError) -> Self {
Self::IO(e.to_string())
}
}
impl From<tokio::task::JoinError> for Error {
fn from(e: tokio::task::JoinError) -> Self {
Self::IO(e.to_string())
}
}
impl From<object_store::path::Error> for Error {
fn from(e: object_store::path::Error) -> Self {
Self::IO(e.to_string())
}
}
impl std::error::Error for Error {}
impl From<Error> for ArrowError {
fn from(value: Error) -> Self {
match value {
Error::Arrow(err) => Self::IoError(err), Error::IO(err) => Self::IoError(err),
Error::Schema(err) => Self::SchemaError(err),
Error::Index(err) => Self::IoError(err),
}
}
}