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 InternalError(String),
25 Custom { code: String, msg: String },
27}
28
29impl FCError {
30 pub fn new(code: &str, msg: String) -> Self {
32 FCError::Custom { code: code.to_string(), msg }
33 }
34}
35
36impl fmt::Display for FCError {
37 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
38 match self {
39 FCError::UnknownCommand(msg) => write!(f, "[E100] Unknown command: {}", msg),
40 FCError::Suggestion(cmd, sugg) => write!(f, "[E101] Did you mean '{}' instead of '{}'?", sugg, cmd),
41 FCError::ParseError(msg) => write!(f, "[E102] Parse error: {}", msg),
42 FCError::InsufficientData(msg) => write!(f, "[E200] Insufficient data: {}", msg),
43 FCError::InvalidArgument(msg) => write!(f, "[E201] Invalid argument: {}", msg),
44 FCError::TypeMismatch { expected, found, context } => write!(f, "[E300] Type mismatch in {}: expected '{}' but found '{}'", context, expected, found),
45 FCError::TypeCoercionFailed { from, to, value } => write!(f, "[E301] Type coercion failed: cannot convert '{}' from '{}' to '{}'", value, from, to),
46 FCError::UnsupportedType(msg) => write!(f, "[E302] Unsupported type: {}", msg),
47 FCError::InternalError(msg) => write!(f, "[E900] Internal error: {}", msg),
48 FCError::Custom { code, msg } => write!(f, "[{}] {}", code, msg),
49 }
50 }
51}
52
53