hiltontj / serde_json_path

Query serde_json Values with JSONPath
https://serdejsonpath.live/
MIT License
51 stars 4 forks source link

Improved Error Handling and Messages #4

Closed hiltontj closed 1 year ago

hiltontj commented 1 year ago

Currently, the error handling and messaging around improperly formatted query strings is not going much further than the standard error capabilities of nom. This leads malformed query strings to produce error messages that are helpful, but need more context and clarity to make for a better user experience.

This is a tracking issue to discuss where the error handling needs improvements. If you are using serde_json_path and find any good examples, please share them here, like so:

JSON Path:

$.foo['bar]

JSON:

{
  "foo": {
    "bar": "baz"
  }
}

Error:

0: at line 1:
$.foo['bar]
      ^
expected '?', found '

1: at line 1, in Alt:
$.foo['bar]
      ^

2: at line 1, in selector:
$.foo['bar]
      ^

3: at line 1, in child long-hand segment:
$.foo['bar]
     ^

Comment:

The error here is because the string literal selector is missing an ending quote ('), but the parser fails saying we missed a ?. Furthermore, rolling up contextual errors at every level of the parsing tree does not add value here.

If you want a convenient place to test out queries and generate examples, try the serde_json_path sandbox

hiltontj commented 1 year ago

This issue is being closed, as although #32 does not make the error system perfect, it definitely changes the context here. Going forward, I will likely create a new issue, or drum up an issue template for submitting parser problems, and cases where error messages could be improved.