1use thiserror::Error;
2
3pub use nom::error::Error as NomError;
4pub type ParseError = NomError<String>;
5
6#[derive(Debug, Clone, PartialEq, Eq, Error)]
7#[error("Error calling function '{fn_name}': {reason}")]
8pub struct FnCallError {
9 pub fn_name: String,
10 #[source]
11 pub reason: Box<EvalError>,
12}
13
14#[derive(Debug, Clone, PartialEq, Eq, Error)]
15#[non_exhaustive]
16pub enum VarAccessError {
17 #[error("Variable access is empty")]
18 EmptyAccess,
19 #[error("Variable not found: {variable}")]
20 VariableNotFound { variable: String },
21 #[error("Object '{object}' does not contain key '{key}'")]
22 ObjectKeyError { object: String, key: String },
23 #[error("Type error: {message}")]
24 TypeError { message: String },
25 #[error("Index out of bounds: {message}")]
26 IndexOutOfBounds { message: String },
27 #[error("Conversion error: {message}")]
28 ConversionError { message: String },
29}
30
31#[derive(Debug, Clone, PartialEq, Eq, Error)]
32#[non_exhaustive]
33pub enum EvalError {
34 #[error(transparent)]
35 VarAccess(#[from] VarAccessError),
36 #[error(transparent)]
37 FnCallError(#[from] FnCallError),
38 #[error("Undefined function: {fn_name}")]
39 FunctionNotFound { fn_name: String },
40 #[error("Type Error: {message}")]
41 TypeError { message: String },
42 #[error("Value Error: {message}")]
43 ValueError { message: String },
44 #[error("Regex Error: {message}")]
45 RegexError { message: String },
46 #[error("Argument Error: Expected {expected} arguments, but got {got}")]
47 ArgumentCount { expected: usize, got: usize },
48 #[error("Cannot call an async function in a sync context")]
49 CallSyncinAsync,
50 #[error("{message}")]
51 Custom { message: String },
52}
53
54#[derive(Debug, Clone, PartialEq, Eq, Error)]
55#[non_exhaustive]
56pub enum Error {
57 #[error(transparent)]
58 Eval(#[from] EvalError),
59 #[error("Parse Error: {0}")]
60 Parse(#[from] ParseError),
61}