Skip to main content

camel_language_api/
error.rs

1use thiserror::Error;
2
3#[derive(Debug, Error)]
4#[non_exhaustive]
5pub enum LanguageError {
6    #[error("parse error in expression `{expr}`: {reason}")]
7    ParseError { expr: String, reason: String },
8
9    #[error("evaluation error: {0}")]
10    EvalError(String),
11
12    #[error("unknown variable: {0}")]
13    UnknownVariable(String),
14
15    #[error("language `{0}` not found in registry")]
16    NotFound(String),
17
18    #[error("feature '{feature}' not supported by language '{language}'")]
19    NotSupported { feature: String, language: String },
20}
21
22impl LanguageError {
23    /// Create an `EvalError` that includes the expression being evaluated.
24    ///
25    /// This preserves the expression context in the error message for easier debugging.
26    pub fn eval_error(expr: &str, message: impl std::fmt::Display) -> Self {
27        LanguageError::EvalError(format!("in expression `{expr}`: {message}"))
28    }
29}