lance 0.1.4

A columnar data format that is 100x faster than Parquet for random access.
Documentation
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements.  See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership.  The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License.  You may obtain a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied.  See the License for the
// specific language governing permissions and limitations
// under the License.

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), // we lose the error type converting to LanceError
            Error::IO(err) => Self::IoError(err),
            Error::Schema(err) => Self::SchemaError(err),
            Error::Index(err) => Self::IoError(err),
        }
    }
}