Debian Codegraph @

third_party/rust/jexl-eval/src/error.rs

raw
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5 use jexl_parser::{ast::OpCode, ParseError, Token};
6
7 use serde_json::Value;
8
9 pub type Result<'a, T, E = EvaluationError<'a>> = std::result::Result<T, E>;
10 #[derive(Debug, thiserror::Error)]
11 pub enum EvaluationError<'a> {
12 #[error("Parsing error: {0}")]
13 ParseError(Box<ParseError<usize, Token<'a>, &'a str>>),
14 #[error("Invalid binary operation, left: {left}, right: {right}, operation: {operation}")]
15 InvalidBinaryOp {
16 left: Value,
17 right: Value,
18 operation: OpCode,
19 },
20 #[error("Unknown transform: {0}")]
21 UnknownTransform(String),
22 #[error("Duplicate object key: {0}")]
23 DuplicateObjectKey(String),
24 #[error("Identifier '{0}' is undefined")]
25 UndefinedIdentifier(String),
26 #[error("Invalid context provided")]
27 InvalidContext,
28 #[error("Invalid index type")]
29 InvalidIndexType,
30 #[error("Invalid json: {0}")]
31 JSONError(#[from] serde_json::Error),
32 #[error("Custom error: {0}")]
33 CustomError(#[from] anyhow::Error),
34 #[error("Invalid filter")]
35 InvalidFilter,
36 }
37
38 impl<'a> From<ParseError<usize, Token<'a>, &'a str>> for EvaluationError<'a> {
39 fn from(cause: ParseError<usize, Token<'a>, &'a str>) -> Self {
40 EvaluationError::ParseError(Box::new(cause))
41 }
42 }