elasticube_core/
error.rs

1//! Error types for ElastiCube
2
3use thiserror::Error;
4
5/// Result type alias for ElastiCube operations
6pub type Result<T> = std::result::Result<T, Error>;
7
8/// Error types that can occur during ElastiCube operations
9///
10/// This enum is marked as `#[non_exhaustive]` to allow adding new error variants
11/// in future versions without breaking changes. When pattern matching, always
12/// include a catch-all arm (`_`) to handle future variants.
13#[non_exhaustive]
14#[derive(Error, Debug)]
15pub enum Error {
16    /// Arrow-related errors
17    #[error("Arrow error: {0}")]
18    Arrow(#[from] arrow::error::ArrowError),
19
20    /// DataFusion-related errors
21    #[error("DataFusion error: {0}")]
22    DataFusion(#[from] datafusion::error::DataFusionError),
23
24    /// IO errors
25    #[error("IO error: {0}")]
26    Io(#[from] std::io::Error),
27
28    /// Schema validation errors
29    #[error("Schema error: {0}")]
30    Schema(String),
31
32    /// Dimension-related errors
33    #[error("Dimension error: {0}")]
34    Dimension(String),
35
36    /// Measure-related errors
37    #[error("Measure error: {0}")]
38    Measure(String),
39
40    /// Hierarchy-related errors
41    #[error("Hierarchy error: {0}")]
42    Hierarchy(String),
43
44    /// Query-related errors
45    #[error("Query error: {0}")]
46    Query(String),
47
48    /// Data source errors
49    #[error("Data source error: {0}")]
50    DataSource(String),
51
52    /// Type conversion errors
53    #[error("Type conversion error: {0}")]
54    TypeConversion(String),
55
56    /// Invalid configuration
57    #[error("Configuration error: {0}")]
58    Config(String),
59
60    /// Builder-related errors
61    #[error("Builder error: {0}")]
62    Builder(String),
63
64    /// Data loading errors
65    #[error("Data error: {0}")]
66    Data(String),
67
68    /// Generic error with custom message
69    #[error("{0}")]
70    Other(String),
71}
72
73impl Error {
74    /// Create a schema error
75    pub fn schema(msg: impl Into<String>) -> Self {
76        Error::Schema(msg.into())
77    }
78
79    /// Create a dimension error
80    pub fn dimension(msg: impl Into<String>) -> Self {
81        Error::Dimension(msg.into())
82    }
83
84    /// Create a measure error
85    pub fn measure(msg: impl Into<String>) -> Self {
86        Error::Measure(msg.into())
87    }
88
89    /// Create a hierarchy error
90    pub fn hierarchy(msg: impl Into<String>) -> Self {
91        Error::Hierarchy(msg.into())
92    }
93
94    /// Create a query error
95    pub fn query(msg: impl Into<String>) -> Self {
96        Error::Query(msg.into())
97    }
98
99    /// Create a data source error
100    pub fn data_source(msg: impl Into<String>) -> Self {
101        Error::DataSource(msg.into())
102    }
103
104    /// Create a configuration error
105    pub fn config(msg: impl Into<String>) -> Self {
106        Error::Config(msg.into())
107    }
108
109    /// Create a builder error
110    pub fn builder(msg: impl Into<String>) -> Self {
111        Error::Builder(msg.into())
112    }
113
114    /// Create a data error
115    pub fn data(msg: impl Into<String>) -> Self {
116        Error::Data(msg.into())
117    }
118
119    /// Create an arrow error
120    pub fn arrow(msg: impl Into<String>) -> Self {
121        Error::Arrow(arrow::error::ArrowError::ExternalError(
122            Box::new(std::io::Error::new(std::io::ErrorKind::Other, msg.into()))
123        ))
124    }
125
126    /// Create an IO error
127    pub fn io(msg: impl Into<String>) -> Self {
128        Error::Io(std::io::Error::new(std::io::ErrorKind::Other, msg.into()))
129    }
130}