use datafusion::error::DataFusionError;
use thiserror::Error;
#[derive(Error, Debug)]
pub enum Error {
#[error("{0} doesn't have the right format")]
InvalidFormat(String),
#[error("Value {0} doesn't have the {1} type.")]
Type(String, String),
#[error("Column {0} not in schema {1}.")]
Schema(String, String),
#[error("Failed to convert {0} to {1}.")]
Conversion(String, String),
#[error("Feature {0} is not supported.")]
NotSupported(String),
#[error("{0} {1} not found.")]
NotFound(String, String),
#[error("datafusion error")]
Datafusion(#[from] datafusion::error::DataFusionError),
#[error("arrowerror")]
Arrow(#[from] datafusion::arrow::error::ArrowError),
#[error("sql parser error")]
SQLParser(#[from] datafusion::sql::sqlparser::parser::ParserError),
#[error("iceberg error")]
Iceberg(#[from] iceberg_rust::error::Error),
#[error("iceberg error")]
IcebergSpec(#[from] iceberg_rust_spec::error::Error),
#[error("serde json error")]
JSONSerde(#[from] serde_json::Error),
#[error("chrono parse error")]
Chrono(#[from] chrono::ParseError),
#[error("io error")]
IO(#[from] std::io::Error),
#[error("channel error")]
FuturesChannel(#[from] futures::channel::mpsc::SendError),
#[error("object store error")]
ObjectStore(#[from] object_store::Error),
#[error("try from slice error")]
TryFromSlice(#[from] std::array::TryFromSliceError),
#[error("try from int error")]
TryFromInt(#[from] std::num::TryFromIntError),
#[error("utf8 error")]
UTF8(#[from] std::str::Utf8Error),
#[error("from utf8 error")]
FromUTF8(#[from] std::string::FromUtf8Error),
#[error("parse int error")]
ParseInt(#[from] std::num::ParseIntError),
}
impl From<Error> for DataFusionError {
fn from(value: Error) -> Self {
DataFusionError::External(Box::new(value))
}
}