toasty_core/error/expression_evaluation_failed.rs
1use super::Error;
2
3/// Error when expression evaluation fails.
4///
5/// This occurs when:
6/// - An expression cannot be evaluated in the current context (DEFAULT, WITH clauses)
7/// - Required data is missing (unresolved references or arguments)
8/// - Type mismatches during evaluation (expected string, got something else)
9/// - Expression evaluation is attempted on non-evaluable constructs
10///
11/// These are runtime evaluation failures, not syntax errors.
12#[derive(Debug)]
13pub(super) struct ExpressionEvaluationFailed {
14 message: Box<str>,
15}
16
17impl std::error::Error for ExpressionEvaluationFailed {}
18
19impl core::fmt::Display for ExpressionEvaluationFailed {
20 fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
21 write!(f, "expression evaluation failed: {}", self.message)
22 }
23}
24
25impl Error {
26 /// Creates an expression evaluation failed error.
27 ///
28 /// This is used when expression evaluation fails at runtime due to:
29 /// - Missing context or data
30 /// - Type mismatches
31 /// - Non-evaluable constructs
32 pub fn expression_evaluation_failed(message: impl Into<String>) -> Error {
33 Error::from(super::ErrorKind::ExpressionEvaluationFailed(
34 ExpressionEvaluationFailed {
35 message: message.into().into(),
36 },
37 ))
38 }
39
40 /// Returns `true` if this error is an expression evaluation failure.
41 pub fn is_expression_evaluation_failed(&self) -> bool {
42 matches!(self.kind(), super::ErrorKind::ExpressionEvaluationFailed(_))
43 }
44}