-
Notifications
You must be signed in to change notification settings - Fork 526
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
Improve JSON body parsing error reporting #2096
Improve JSON body parsing error reporting #2096
Conversation
3cada6f
to
63f675a
Compare
I had a few problems with starting the server for the integration tests, so it took some time to fix them (despite none of the issues being in tests that needed the servers). Reinforcing what I said in the comment above, I don't know if you want to change the Moreover, all the possible user errors catch techniques added in this PR degrade performance, obv. almost nothing in a modern computer so it's next to irrelevant, but I still think that generating better error messages is more important. When I fixed the errors I also added another check when braces are unclosed, so there is this error message:
|
Hi @robozati Thanks for your PR. We just need some time to review it, @fabricereix will look at it next week (he's on holiday), as he's implemented the JSON parser. Don't hesitate to send us any issues/difficulties that you encounter (with how to launch integration tests for instance). We can improve the docs also if things are not well explained. |
I also prefer to stick to one only variant |
From the changes in current integ test
The error message could be improved to I don't really find that the new error message is more relevant
Adding a closing brace will still produce an invalid JSON |
I changed Also, I added a new test to account for names that could not be resolved, as your last code snippet. So the json below now fails with:
If there is only punctuation:
However, the test below still produces the same error. @fabricereix are you ok with this, or do you want to first check if there is a a valid element, then check for the braces?
EDIT: I forgot to run cargo fmt on parser/mod.rs, but I am planning to rebase all the commits into one in the end of the review, so this isn't important for now. |
I have updated the issue with expected error messages. We can add them as integration tests. tests_error_parser/json_object_trailing_comma.hurl
tests_error_parser/json_list_trailing_comma.hurl
tests_error_parser/json_object_expecting_element.hurl (replaces json_unexpected_character.hurl)
tests_error_parser/json_list_expecting_element.hurl
|
Okay, will do this later today or tomorrow and open this PR again. |
@fabricereix I made the changes that you asked, but due to expecting an element having greater precedence to unclosed braces, I removed the unclosed braces check because it doesn't do nothing anymore. Ex.:
This is because the parser looks for an element on HTTP, but this isn't an element, so the expecting element error fires. |
/accept |
🕗 /accept is running, please wait for completion. |
Adds more checks to account for empty elements, commas after the last element that shouldn't be there and braces not closed.
new check to account for unresolved names
🔨 Auto rebase from
|
🕗 /accept is running, please wait for completion. |
13b6e3d
to
97a02f3
Compare
✅ Pull request merged and closed by |
Closes #2056.
This add more checks on
list_value
,object_value
andobject_element
to account for empty elements, reporting that there is one more comma in the first two functions and an empty element in the last. Makes sense because these errors are very common, and the user most likely forgot that there is one more comma in the first two cases.Problem is that I don't know if you would like to change
ParserError::Json
toParserError::Json(AnotherEnum)
, so I changed one existing member (Unexpected
) that wasn't used in the rest of the code to account for unexpected commas and added another member,ExpectedAnElementInJson
. All the three have the same description message, so there is repetition.Before this patch:
After:
Also:
And: