use arrow::datatypes::DataType;
use arrow::error::ArrowError;
#[derive(Debug, thiserror::Error)]
#[error("{record_type}: {kind}")]
pub struct Error {
pub record_type: &'static str,
pub kind: ErrorKind,
}
#[derive(Debug, thiserror::Error)]
pub enum ErrorKind {
#[error(
"Missing required column {column:?}. If the column is allowed to be missing, declare the field as `Option<…>`"
)]
MissingColumn { column: String },
#[error("Column {column:?}: expected {expected}, found {actual:?}")]
WrongDatatype {
column: String,
expected: String,
actual: DataType,
},
#[error(
"Unexpected column {column:?}. Either add it to the struct, or accept unknown columns with a `#[quiver(extra_columns)]` field"
)]
UnexpectedColumn { column: String },
#[error(
"Column {column:?} has {null_count} null(s) at a non-nullable level. Use `Option<…>` in the logical type to allow nulls"
)]
UnexpectedNulls { column: String, null_count: usize },
#[error("Column {column:?}: expected a {expected}, found datatype {actual:?}")]
WrongArrayType {
column: String,
expected: String,
actual: DataType,
},
#[error("Failed to build the record batch: {0}")]
BuildRecordBatch(ArrowError),
}
impl From<Error> for ArrowError {
fn from(err: Error) -> Self {
if let ErrorKind::BuildRecordBatch(arrow_err) = err.kind {
arrow_err
} else {
Self::ExternalError(Box::new(err))
}
}
}