Skip to main content

nd_arrow_array/
error.rs

1//! Error type for nd arrays.
2
3use arrow::error::ArrowError;
4
5/// Errors raised by nd array construction, encoding and decoding.
6#[derive(Debug, thiserror::Error)]
7pub enum NdError {
8    /// An error from an Arrow kernel.
9    #[error(transparent)]
10    Arrow(#[from] ArrowError),
11    /// Dimension names or sizes are not valid.
12    #[error("invalid dimensions: {0}")]
13    InvalidDimensions(String),
14    /// Shapes do not match or do not broadcast.
15    #[error("shape mismatch: {0}")]
16    ShapeMismatch(String),
17    /// An attribute is not valid.
18    #[error("invalid attribute: {0}")]
19    InvalidAttribute(String),
20    /// Stored data does not follow the nd encoding.
21    #[error("invalid nd encoding: {0}")]
22    InvalidEncoding(String),
23    /// Types or schemas do not match.
24    #[error("schema mismatch: {0}")]
25    SchemaMismatch(String),
26    /// An argument is not valid.
27    #[error("invalid argument: {0}")]
28    InvalidArgument(String),
29    /// The operation does not support the input.
30    #[error("not supported: {0}")]
31    NotSupported(String),
32}
33
34impl From<NdError> for ArrowError {
35    fn from(error: NdError) -> Self {
36        match error {
37            NdError::Arrow(e) => e,
38            other => ArrowError::InvalidArgumentError(other.to_string()),
39        }
40    }
41}
42
43/// A result with [`NdError`] as the default error.
44pub type Result<T, E = NdError> = std::result::Result<T, E>;
45
46macro_rules! nd_err {
47    ($variant:ident, $($arg:tt)*) => {
48        $crate::error::NdError::$variant(format!($($arg)*))
49    };
50}
51
52pub(crate) use nd_err;