evalx/error/
mod.rs

1use serde_json::Value;
2use crate::operator::Operator;
3use quick_error::quick_error;
4
5
6quick_error! {
7    /// Expression parsing error
8    #[derive(Debug, PartialEq, Eq)]
9    pub enum Error {
10        /// Unsupported operator yet.
11        UnsupportedOperator(operator: String) {
12            display("Unsupported operator: {:?}", operator)
13        }
14        /// This operator does not support execution.
15        CanNotExec(operator: Operator) {
16            display("This operator does not support execution: {:?}", operator)
17        }
18        /// Your expression may start with non-value operator like ( + * )
19        StartWithNonValueOperator {
20            display("Your expression may start with non-value operator like ( + * ).")
21        }
22        /// Unpaired brackets, left brackets count does not equal right brackets count
23        UnpairedBrackets {
24            display("Unpaired brackets, left brackets count does not equal right brackets count.")
25        }
26        /// Duplicate values node, you may have (2 3) but there is no operators between them
27        DuplicateValueNode {
28            display("Duplicate values node, you may have (2 3) but there is no operators between them.")
29        }
30        /// Duplicate operators node, you may have (+ +) but there is no values between them
31        DuplicateOperatorNode {
32            display("Duplicate operators node, you may have (+ +) but there is no values between them.")
33        }
34        /// You have a comma(,) , but there is no function in front of it.
35        CommaNotWithFunction {
36            display("You have a comma(,) , but there is no function in front of it.")
37        }
38        /// You have empty brackets () , but there is no function in front of it.
39        BracketNotWithFunction {
40            display("You have empty brackets () , but there is no function in front of it.")
41        }
42        /// Function not exists.
43        FunctionNotExists(ident: String) {
44            display("Function not exists: {}", ident)
45        }
46        /// Expected a boolean but the given value isn't.
47        ExpectedBoolean(value: Value) {
48            display("Expected a boolean, found: {}", value)
49        }
50        /// Expected ident.
51        ExpectedIdentifier {
52            display("Expected ident.")
53        }
54        /// Expected array.
55        ExpectedArray {
56            display("Expected array.")
57        }
58        /// Expected object.
59        ExpectedObject {
60            display("Expected object.")
61        }
62        /// Expect number.
63        ExpectedNumber {
64            display("Expected number.")
65        }
66        /// Failed to parse, no final expression.
67        NoFinalNode {
68            display("Failed to parse, no final expression.")
69        }
70        /// The number of arguments is greater than the maximum limit.
71        ArgumentsGreater(max: usize) {
72            display("The number of arguments is greater than the maximum limit: {}", max)
73        }
74        /// The number of arguments is less than the minimum limit.
75        ArgumentsLess(min: usize) {
76            display("The number of arguments is less than the minimum limit: {}", min)
77        }
78        /// This two value types are different or do not support mathematical calculations.
79        UnsupportedTypes(a: String, b: String) {
80            display("This two value types are different or do not support mathematical calculations: {}, {}", a, b)
81        }
82        /// Invalid range expression like `1..2..3`
83        InvalidRange(ident: String) {
84            display("Invalid range expression: {}", ident)
85        }
86        /// Can not add child node.
87        CanNotAddChild {
88            display("Can not add child node.")
89        }
90        /// Custom error.
91        Custom(detail: String) {
92            display("{}", detail)
93        }
94    }
95}