1use thiserror::Error;
2
3#[derive(Error, Debug)]
4pub enum DtransformError {
5 #[error("Parse error: {0}")]
6 ParseError(String),
7
8 #[error("Column not found: {0}")]
9 ColumnNotFound(String),
10
11 #[error("Type mismatch: expected {expected}, got {got}")]
12 TypeMismatch { expected: String, got: String },
13
14 #[error("I/O error: {0}")]
15 IoError(#[from] std::io::Error),
16
17 #[error("Polars error: {0}")]
18 PolarsError(#[from] polars::error::PolarsError),
19
20 #[error("Invalid operation: {0}")]
21 InvalidOperation(String),
22
23 #[error("Variable not found: {0}")]
24 VariableNotFound(String),
25
26 #[error("Regex error: {0}")]
27 RegexError(#[from] regex::Error),
28
29 #[error("Pest parse error: {0}")]
30 PestError(String),
31
32 #[error("Readline error: {0}")]
33 ReadlineError(String),
34}
35
36pub type Result<T> = std::result::Result<T, DtransformError>;
37
38impl DtransformError {
39 pub fn display_friendly(&self) -> String {
40 match self {
41 DtransformError::ColumnNotFound(col) => {
42 format!(
43 "Column '{}' not found.\nUse .schema to see all columns.",
44 col
45 )
46 }
47 DtransformError::ParseError(msg) => {
48 format!("Syntax error: {}\nSee examples with .help", msg)
49 }
50 DtransformError::VariableNotFound(var) => {
51 format!(
52 "Variable '{}' not found.\nUse .vars to see all variables.",
53 var
54 )
55 }
56 _ => self.to_string(),
57 }
58 }
59}