use std::fmt;
use crate::types::ValueKind;
#[derive(Debug, PartialEq)]
pub enum FCError {
UnknownCommand(String),
Suggestion(String, String), ParseError(String),
InsufficientData(String), InvalidArgument(String),
TypeMismatch { expected: String, found: String, context: String },
TypeCoercionFailed { from: ValueKind, to: ValueKind, value: String },
UnsupportedType(String),
BackendError(String),
DuckDBConnectionError(String),
DuckDBQueryError(String),
DuckDBDataConversionError(String),
InternalError(String),
Custom { code: String, msg: String },
}
impl FCError {
pub fn new(code: &str, msg: String) -> Self {
FCError::Custom { code: code.to_string(), msg }
}
}
impl fmt::Display for FCError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
FCError::UnknownCommand(msg) => write!(f, "[E100] Unknown command: {}", msg),
FCError::Suggestion(cmd, sugg) => write!(f, "[E101] Did you mean '{}' instead of '{}'?", sugg, cmd),
FCError::ParseError(msg) => write!(f, "[E102] Parse error: {}", msg),
FCError::InsufficientData(msg) => write!(f, "[E200] Insufficient data: {}", msg),
FCError::InvalidArgument(msg) => write!(f, "[E201] Invalid argument: {}", msg),
FCError::TypeMismatch { expected, found, context } => write!(f, "[E300] Type mismatch in {}: expected '{}' but found '{}'", context, expected, found),
FCError::TypeCoercionFailed { from, to, value } => write!(f, "[E301] Type coercion failed: cannot convert '{}' from '{}' to '{}'", value, from, to),
FCError::UnsupportedType(msg) => write!(f, "[E302] Unsupported type: {}", msg),
FCError::BackendError(msg) => write!(f, "[E400] Backend error: {}", msg),
FCError::DuckDBConnectionError(msg) => write!(f, "[E401] DuckDB connection error: {}", msg),
FCError::DuckDBQueryError(msg) => write!(f, "[E402] DuckDB query error: {}", msg),
FCError::DuckDBDataConversionError(msg) => write!(f, "[E403] DuckDB data conversion error: {}", msg),
FCError::InternalError(msg) => write!(f, "[E900] Internal error: {}", msg),
FCError::Custom { code, msg } => write!(f, "[{}] {}", code, msg),
}
}
}
impl std::error::Error for FCError {}