Skip to main content

filter_expr_evaler/
error.rs

1use crate::ValueType;
2
3#[derive(Debug, thiserror::Error)]
4pub enum Error {
5    #[error("internal: {0}")]
6    Internal(String),
7
8    #[error("invalid value {0}")]
9    InvalidValue(String),
10
11    #[error("type mismatch: expected same type for comparison, got {0:?} and {1:?}")]
12    TypeMismatch(String, String),
13
14    /// Failed to get the variable.
15    #[error("failed to get the variable {var:?}: {error}")]
16    FailedToGetVar { var: String, error: String },
17
18    /// The variable is not found.
19    #[error("no such variable {var:?}")]
20    NoSuchVar { var: String },
21
22    /// The function is not found.
23    #[error("no such function {function:?}")]
24    NoSuchFunction { function: String },
25
26    /// The method is not found.
27    #[error("no such method {method:?} for type {obj_type:?}")]
28    NoSuchMethod { method: String, obj_type: ValueType },
29
30    /// Invalid argument count for the given function.
31    #[error(
32        "invalid argument count for function {function:?}: expected {expected} argument(s), but got {got} argument(s)"
33    )]
34    InvalidArgumentCountForFunction {
35        function: String,
36        expected: usize,
37        got: usize,
38    },
39
40    /// Invalid argument type for the given function's index-th argument.
41    #[error(
42        "invalid argument type for function {function:?}'s index {index} argument: expected {expected:?}, got {got:?}"
43    )]
44    InvalidArgumentTypeForFunction {
45        function: String,
46        index: usize,
47        expected: ValueType,
48        got: ValueType,
49    },
50
51    /// Invalid argument count for the given method.
52    #[error(
53        "invalid argument count for method {method:?}: expected {expected} argument(s), but got {got} argument(s)"
54    )]
55    InvalidArgumentCountForMethod {
56        method: String,
57        expected: usize,
58        got: usize,
59    },
60
61    /// Invalid argument type for the given method's index-th argument.
62    #[error(
63        "invalid argument type for method {method:?}'s index {index} argument: expected {expected:?}, got {got:?}"
64    )]
65    InvalidArgumentTypeForMethod {
66        method: String,
67        index: usize,
68        expected: ValueType,
69        got: ValueType,
70    },
71}