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<PolarsError> for EngineError {
45 fn from(e: PolarsError) -> Self {
46 let msg = e.to_string();
47 match &e {
48 PolarsError::ColumnNotFound(_) => EngineError::NotFound(msg),
49 PolarsError::InvalidOperation(_) => EngineError::User(msg),
50 PolarsError::ComputeError(_) => EngineError::Internal(msg),
51 PolarsError::IO { .. } => EngineError::Io(msg),
52 _ => EngineError::Other(msg),
53 }
54 }
55}
56
57impl From<serde_json::Error> for EngineError {
58 fn from(e: serde_json::Error) -> Self {
59 EngineError::Internal(e.to_string())
60 }
61}
62
63impl From<std::io::Error> for EngineError {
64 fn from(e: std::io::Error) -> Self {
65 EngineError::Io(e.to_string())
66 }
67}