Skip to main content

robin_sparkless_core/
error.rs

1//! Engine error type for embedders.
2//!
3//! Use [`EngineError`] when you want to map robin-sparkless and Polars errors
4//! to a single type (e.g. for FFI or CLI) without depending on Polars error types.
5//!
6//! Note: `From<PolarsError>` for `EngineError` is implemented in the main robin-sparkless
7//! crate, which has a Polars dependency.
8
9use std::fmt;
10
11/// Unified error type for robin-sparkless operations.
12///
13/// Embedders (Python, Node, CLI) can map these variants to native errors
14/// without depending on `PolarsError`.
15#[derive(Debug)]
16pub enum EngineError {
17    /// User-facing error (invalid input, unsupported operation).
18    User(String),
19    /// Internal / compute error.
20    Internal(String),
21    /// I/O error (file not found, permission, etc.).
22    Io(String),
23    /// SQL parsing or execution error.
24    Sql(String),
25    /// Resource not found (column, table, file).
26    NotFound(String),
27    /// Other / unclassified.
28    Other(String),
29}
30
31impl fmt::Display for EngineError {
32    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
33        match self {
34            EngineError::User(s) => write!(f, "user error: {s}"),
35            EngineError::Internal(s) => write!(f, "internal error: {s}"),
36            EngineError::Io(s) => write!(f, "io error: {s}"),
37            EngineError::Sql(s) => write!(f, "sql error: {s}"),
38            EngineError::NotFound(s) => write!(f, "not found: {s}"),
39            EngineError::Other(s) => write!(f, "{s}"),
40        }
41    }
42}
43
44impl std::error::Error for EngineError {}
45
46impl From<serde_json::Error> for EngineError {
47    fn from(e: serde_json::Error) -> Self {
48        EngineError::Internal(e.to_string())
49    }
50}
51
52impl From<std::io::Error> for EngineError {
53    fn from(e: std::io::Error) -> Self {
54        EngineError::Io(e.to_string())
55    }
56}