1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
use pest::iterators::Pairs;
use thiserror::Error;

use super::parser::Rule;

#[derive(Error, Debug)]
#[allow(clippy::large_enum_variant)]
pub enum JsonPathParserError<'a> {
    #[error("Failed to parse rule: {0}")]
    PestError(#[from] pest::error::Error<Rule>),
    #[error("Failed to parse JSON: {0}")]
    JsonParsingError(#[from] serde_json::Error),
    #[error("{0}")]
    ParserError(String),
    #[error("Unexpected rule {0:?} when trying to parse logic atom: {1:?}")]
    UnexpectedRuleLogicError(Rule, Pairs<'a, Rule>),
    #[error("Unexpected `none` when trying to parse logic atom: {0:?}")]
    UnexpectedNoneLogicError(Pairs<'a, Rule>),
}

pub fn parser_err(cause: &str) -> JsonPathParserError<'_> {
    JsonPathParserError::ParserError(format!("Failed to parse JSONPath: {cause}"))
}