Module rsonpath_lib::query::errors

source ·
Expand description

Error types for the query module.

The main error type is ParseErrorReport, which contains all ParseErrors encountered during parsing.

Examples

Retrieving the part of input that caused a parse error:

use rsonpath_lib::query::JsonPathQuery;
use rsonpath_lib::query::errors::QueryError;

let query_str =
    "$.prop..invalid$chars.this_is_fine";
//                  ^     ^
//                  |_____|________________ start_idx of the error
//                        |________________ at this point the parser recovers
//                  ^^^^^^_________________ error length of 6
let result = JsonPathQuery::parse(query_str);

match result {
    Err(QueryError::ParseError { report }) => {
        assert_eq!(report.errors().count(), 1);
        let parse_error = report.errors().next().unwrap();
        assert_eq!(parse_error.start_idx, 15);
        assert_eq!(parse_error.len, 6);
        let start = parse_error.start_idx;
        let end = parse_error.start_idx + parse_error.len;
        let invalid_tokens = &query_str[start..end];
        assert_eq!(invalid_tokens, "$chars");
    },
    _ => unreachable!(),
}

Structs

Single error raised during parsing, defined as the contiguous sequence of characters that caused the error.
Error report created during the parser’s run over a single input string.

Enums

Errors raised by the query parser.