#[derive(Debug, Clone)]
pub enum EvaluationError {
Message(String),
InvalidArguments(String),
UnknownFunction(String),
TypeError { expected: String, actual: String },
IndexOutOfBounds { index: i64, length: usize },
FieldNotFound(String),
SyntaxError(String),
ConditionError(String),
CaughtError(Box<EvaluationError>),
}
impl EvaluationError {
pub fn new(message: String) -> Self {
Self::Message(message)
}
}
impl std::fmt::Display for EvaluationError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
EvaluationError::Message(msg) => {
write!(f, "Evaluation error: {msg}")
}
EvaluationError::InvalidArguments(msg) => {
write!(f, "Invalid arguments: {msg}")
}
EvaluationError::UnknownFunction(name) => {
write!(f, "Unknown function: {name}")
}
EvaluationError::TypeError { expected, actual } => {
write!(f, "Type error: expected {expected}, got {actual}")
}
EvaluationError::IndexOutOfBounds { index, length } => {
write!(f, "Index out of bounds: index {index}, length {length}")
}
EvaluationError::FieldNotFound(field) => {
write!(f, "Field not found: {field}")
}
EvaluationError::SyntaxError(msg) => {
write!(f, "Syntax error: {msg}")
}
EvaluationError::ConditionError(msg) => {
write!(f, "Condition error: {msg}")
}
EvaluationError::CaughtError(inner) => {
write!(f, "Caught error: {inner}")
}
}
}
}
impl std::error::Error for EvaluationError {}