1use polars::error::PolarsError;
7use std::fmt;
8
9#[derive(Debug)]
14pub enum EngineError {
15 User(String),
17 Internal(String),
19 Io(String),
21 Sql(String),
23 NotFound(String),
25 Other(String),
27}
28
29impl fmt::Display for EngineError {
30 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
31 match self {
32 EngineError::User(s) => write!(f, "user error: {s}"),
33 EngineError::Internal(s) => write!(f, "internal error: {s}"),
34 EngineError::Io(s) => write!(f, "io error: {s}"),
35 EngineError::Sql(s) => write!(f, "sql error: {s}"),
36 EngineError::NotFound(s) => write!(f, "not found: {s}"),
37 EngineError::Other(s) => write!(f, "{s}"),
38 }
39 }
40}
41
42impl std::error::Error for EngineError {}
43
44impl From<robin_sparkless_core::EngineError> for EngineError {
45 fn from(e: robin_sparkless_core::EngineError) -> Self {
46 use robin_sparkless_core::EngineError as Core;
47 match e {
48 Core::User(s) => EngineError::User(s),
49 Core::Internal(s) => EngineError::Internal(s),
50 Core::Io(s) => EngineError::Io(s),
51 Core::Sql(s) => EngineError::Sql(s),
52 Core::NotFound(s) => EngineError::NotFound(s),
53 Core::Other(s) => EngineError::Other(s),
54 }
55 }
56}
57
58impl From<PolarsError> for EngineError {
59 fn from(e: PolarsError) -> Self {
60 let msg = e.to_string();
61 match &e {
62 PolarsError::ColumnNotFound(_) => EngineError::NotFound(msg),
63 PolarsError::InvalidOperation(_) => EngineError::User(msg),
64 PolarsError::ComputeError(_) => EngineError::Internal(msg),
65 PolarsError::IO { .. } => EngineError::Io(msg),
66 _ => EngineError::Other(msg),
67 }
68 }
69}
70
71impl From<serde_json::Error> for EngineError {
72 fn from(e: serde_json::Error) -> Self {
73 EngineError::Internal(e.to_string())
74 }
75}
76
77impl From<std::io::Error> for EngineError {
78 fn from(e: std::io::Error) -> Self {
79 EngineError::Io(e.to_string())
80 }
81}