1use std::fmt;
4use crate::types::ValueKind;
5
6#[derive(Debug, PartialEq)]
8pub enum FCError {
9 UnknownCommand(String),
11 Suggestion(String, String), ParseError(String),
13
14 InsufficientData(String), InvalidArgument(String), TypeMismatch { expected: String, found: String, context: String },
20 TypeCoercionFailed { from: ValueKind, to: ValueKind, value: String },
21 UnsupportedType(String),
22
23 BackendError(String),
25 DuckDBConnectionError(String),
27 DuckDBQueryError(String),
28 DuckDBDataConversionError(String),
29
30 InternalError(String),
32 Custom { code: String, msg: String },
34}
35
36impl FCError {
37 pub fn new(code: &str, msg: String) -> Self {
39 FCError::Custom { code: code.to_string(), msg }
40 }
41}
42
43impl fmt::Display for FCError {
44 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
45 match self {
46 FCError::UnknownCommand(msg) => write!(f, "[E100] Unknown command: {}", msg),
47 FCError::Suggestion(cmd, sugg) => write!(f, "[E101] Did you mean '{}' instead of '{}'?", sugg, cmd),
48 FCError::ParseError(msg) => write!(f, "[E102] Parse error: {}", msg),
49 FCError::InsufficientData(msg) => write!(f, "[E200] Insufficient data: {}", msg),
50 FCError::InvalidArgument(msg) => write!(f, "[E201] Invalid argument: {}", msg),
51 FCError::TypeMismatch { expected, found, context } => write!(f, "[E300] Type mismatch in {}: expected '{}' but found '{}'", context, expected, found),
52 FCError::TypeCoercionFailed { from, to, value } => write!(f, "[E301] Type coercion failed: cannot convert '{}' from '{}' to '{}'", value, from, to),
53 FCError::UnsupportedType(msg) => write!(f, "[E302] Unsupported type: {}", msg),
54 FCError::BackendError(msg) => write!(f, "[E400] Backend error: {}", msg),
55 FCError::DuckDBConnectionError(msg) => write!(f, "[E401] DuckDB connection error: {}", msg),
56 FCError::DuckDBQueryError(msg) => write!(f, "[E402] DuckDB query error: {}", msg),
57 FCError::DuckDBDataConversionError(msg) => write!(f, "[E403] DuckDB data conversion error: {}", msg),
58 FCError::InternalError(msg) => write!(f, "[E900] Internal error: {}", msg),
59 FCError::Custom { code, msg } => write!(f, "[{}] {}", code, msg),
60 }
61 }
62}
63
64impl std::error::Error for FCError {}