Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add custom error with variants to parser module #50

Merged
merged 3 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ serde_json = "1.0"
regex = "1"
pest = "2.0"
pest_derive = "2.0"
thiserror = "1.0.50"

[dev-dependencies]
lazy_static = "1.0"
18 changes: 18 additions & 0 deletions src/parser/errors.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use pest::iterators::Pairs;
use thiserror::Error;

use super::parser::Rule;

#[derive(Error, Debug)]
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>),
}
2 changes: 2 additions & 0 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
//! The parser for the jsonpath.
//! The module grammar denotes the structure of the parsing grammar

pub mod errors;
mod macros;
pub mod model;
#[allow(clippy::module_inception)]
#[allow(clippy::result_large_err)]
pub mod parser;
Loading
Loading