-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
export errors and reduce box usage (#67)
* Export Error to library, at the cost that the internal Pairs is now stringified * get rid of Json parsing for boolean and put the PestError in a Box (especially to keep the results small in Ok(_) case) * make `json_path_instance` work without PathInstance, which is a Box<dyn> type and thus needs an additinal vtable for each search
- Loading branch information
Showing
7 changed files
with
207 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,27 @@ | ||
use pest::iterators::Pairs; | ||
use thiserror::Error; | ||
|
||
use super::parser::Rule; | ||
|
||
#[derive(Error, Debug)] | ||
#[allow(clippy::large_enum_variant)] | ||
pub enum JsonPathParserError<'a> { | ||
pub enum JsonPathParserError { | ||
#[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}")) | ||
PestError(#[from] Box<pest::error::Error<Rule>>), | ||
#[error("Unexpected rule {0:?} when trying to parse logic atom: {1} within {2}")] | ||
UnexpectedRuleLogicError(Rule, String, String), | ||
#[error("Unexpected `none` when trying to parse logic atom: {0} within {1}")] | ||
UnexpectedNoneLogicError(String, String), | ||
#[error("Pest returned successful parsing but did not produce any output, that should be unreachable due to .pest definition file: SOI ~ chain ~ EOI")] | ||
UnexpectedPestOutput, | ||
#[error("expected a `Rule::path` but found nothing")] | ||
NoRulePath, | ||
#[error("expected a `JsonPath::Descent` but found nothing")] | ||
NoJsonPathDescent, | ||
#[error("expected a `JsonPath::Field` but found nothing")] | ||
NoJsonPathField, | ||
#[error("expected a `f64` or `i64`, but got {0}")] | ||
InvalidNumber(String), | ||
#[error("Invalid toplevel rule for JsonPath: {0:?}")] | ||
InvalidTopLevelRule(Rule), | ||
#[error("Failed to get inner pairs for {0}")] | ||
EmptyInner(String), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.