num_parser/out/
mod.rs

1mod display;
2
3use crate::objects::Request;
4
5use super::{
6    token::tokentype::TokenType,
7    value::{valuetype::ValueType, Value},
8};
9
10/// A type alias for `Result<T, ErrorType>`
11pub type EvalResult<T> = Result<T, ErrorType>;
12
13/// Contains all possible error messages. Implements `Display`.
14///
15/// ```
16/// use num_parser::*;
17///
18/// let msg = ErrorType::DivideByZero{
19///     numerator: Value::from(2)
20/// }.to_string();
21///
22/// assert_eq!(msg, "MATH ERROR: trying to divide 2 by zero.");
23/// ```
24#[derive(Debug)]
25pub enum ErrorType {
26    /// A mismatched type.
27    TypeError {
28        expected: ValueType,
29        given: ValueType,
30    },
31    /// An unknown token found while parsing the string.
32    UnknownToken { token: String },
33    /// A known token placed in an invalid position.
34    InvalidTokenPosition { token: TokenType },
35    /// A failed cast due to data loss.
36    FailedCast {
37        value: Value,
38        from: ValueType,
39        to: ValueType,
40    },
41    /// Two arrays with different lengths.
42    MismatchedArrayLengths {
43        first: usize,
44        second: usize,
45        operation_name: &'static str,
46    },
47    /// Trying to divide by zero.
48    DivideByZero { numerator: Value },
49    /// A token which is not an operator being used as such.
50    NotAnOperator { token: TokenType },
51    /// An invalid closing bracket.
52    InvalidClosingBracket,
53    /// A missing closing bracket.
54    MissingClosingBracket,
55    /// A missing left argument for an operator.
56    MissingOperatorArgument { token: TokenType },
57    /// An error occurred while parsing a literal.
58    FailedParse { value: String },
59    /// Two brackets with nothing inside.
60    EmptyBrackets,
61    /// A function call with the wrong function arguments amount.
62    WrongFunctionArgumentsAmount {
63        func_name: String,
64        expected: u8,
65        given: u8,
66    },
67    /// A function with no parameters.
68    MissingFunctionParameters { func_name: String },
69    /// An invalid declaration.
70    InvalidDeclaration,
71    /// An unknown function.
72    UnknownFunction { func_name: String },
73    /// An unknown variable.
74    UnknownVar { var_name: String },
75    /// A reserved variable name.
76    ReservedVarName { var_name: String },
77    /// A reserved function name.
78    ReservedFunctionName { func_name: String },
79    /// An empty union ,,
80    EmptyUnion,
81    /// Invalid request for a static context
82    InvalidMutableContext { request: Request },
83    /// Reached maximum recursion depth.
84    RecursionDepthLimitReached { limit: u32 },
85
86    /// An error wrapper to add additional information.
87    ErrorDuring {
88        operation_name: &'static str,
89        error: Box<ErrorType>,
90    },
91    /// An error due to a missing implementation or a bug. This should
92    /// never occur.
93    InternalError { message: String },
94}
95
96impl std::error::Error for ErrorType {}