pub enum ExprError {
Parse(ParseFloatError),
Tokenizer(String),
Syntax(String),
UnmatchedParenthesis {
position: usize,
found: String,
},
UnknownVariable {
name: String,
},
UnknownFunction {
name: String,
},
InvalidFunctionCall {
name: String,
expected: usize,
found: usize,
},
ArrayIndexOutOfBounds {
name: String,
index: usize,
len: usize,
},
AttributeNotFound {
base: String,
attr: String,
},
Other(String),
RecursionLimit(String),
}
Expand description
Error type for expression parsing and evaluation.
This enum represents all possible errors that can occur during expression parsing, tokenization, and evaluation. It provides specific error variants with detailed information to help diagnose and fix issues.
Variants§
Parse(ParseFloatError)
Error when parsing a floating point number.
This occurs when a string cannot be converted to a floating point number. For example, “3.a” is not a valid floating point number.
Tokenizer(String)
Error during lexical analysis (tokenization).
This occurs when the tokenizer encounters invalid tokens or unknown characters that cannot be processed. The string contains a detailed error message.
Syntax(String)
Error during syntax analysis.
This occurs when the parser encounters unexpected tokens, incorrect expression structure, or other syntax issues. The string contains a detailed error message.
UnmatchedParenthesis
Error for unmatched parentheses in an expression.
This provides the position of the unmatched parenthesis and the specific parenthesis character that was found without a matching pair.
UnknownVariable
Error when a variable referenced in an expression is not defined.
To resolve this error, make sure the variable is registered in the
evaluation context using EvalContext::set_parameter
.
UnknownFunction
Unknown function error
This error is returned when a function is called that is not registered in the context
and is not a built-in (if built-ins are enabled). If the no-builtin-math
feature is enabled,
users must register their own native functions for all required math operations.
To resolve this error, register a native function with EvalContext::register_native_function
or an expression function with EvalContext::register_expression_function
.
InvalidFunctionCall
Error when a function is called with the wrong number of arguments.
This occurs when a function is called with fewer or more arguments than it expects. The error includes the function name, the expected number of arguments, and the actual number of arguments provided.
Fields
ArrayIndexOutOfBounds
Error when an array index is out of bounds.
This occurs when trying to access an array element with an index that exceeds the array’s length. The error includes the array name, the attempted index, and the actual length of the array.
Fields
AttributeNotFound
Error when an attribute access is attempted on an object that doesn’t have that attribute.
This occurs when using the dot notation (e.g., object.attribute
) and the attribute
does not exist on the specified object.
Other(String)
General-purpose error for any other error conditions.
This is used for errors that don’t fit into other specific categories. The string contains a detailed error message.
RecursionLimit(String)
Error when the recursion limit is exceeded during expression evaluation.
This usually happens with deeply nested expressions or recursive function calls. To resolve this, simplify the expression or increase the recursion limit if possible.