Skip to main content

orbital_data/
projection.rs

1use std::fmt;
2
3use crate::DataType;
4
5/// Errors raised when extracting or projecting chart columns from a [`crate::Dataset`].
6#[derive(Clone, Debug, PartialEq, Eq)]
7pub enum ProjectionError {
8    /// Referenced field is not present in the dataset schema.
9    UnknownField { field: String },
10    /// Cell value variant does not match the expected column type.
11    TypeMismatch {
12        field: String,
13        expected: &'static str,
14        got: DataType,
15    },
16    /// Dataset has no records.
17    EmptyDataset,
18    /// Extracted column length does not match the expected row count.
19    LengthMismatch {
20        field: String,
21        expected: usize,
22        got: usize,
23    },
24    /// Binding feature not yet supported by the projection engine.
25    UnsupportedBinding { reason: String },
26}
27
28impl fmt::Display for ProjectionError {
29    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
30        match self {
31            Self::UnknownField { field } => write!(f, "unknown field '{field}'"),
32            Self::TypeMismatch {
33                field,
34                expected,
35                got,
36            } => write!(f, "field '{field}' expected {expected}, got {got:?}"),
37            Self::EmptyDataset => write!(f, "dataset has no records"),
38            Self::LengthMismatch {
39                field,
40                expected,
41                got,
42            } => write!(
43                f,
44                "field '{field}' length mismatch: expected {expected}, got {got}"
45            ),
46            Self::UnsupportedBinding { reason } => write!(f, "unsupported binding: {reason}"),
47        }
48    }
49}
50
51impl std::error::Error for ProjectionError {}