stleary / JSON-java

A reference implementation of a JSON package in Java.
http://stleary.github.io/JSON-java/index.html
Other
4.54k stars 2.56k forks source link

extend syntax error information #879

Closed Simulant87 closed 7 months ago

Simulant87 commented 8 months ago

The syntax error contains only the index of the not parsable character. It might be helpful to indclude more information like the current character and why it is not allowed at this place.

stleary commented 8 months ago

@Simulant87 Can you include unit tests for the new behavior?

Simulant87 commented 8 months ago

@stleary Sure, I added tests for the new exception messages.

I am not sure, if you like my latest change, explainging the numbers in the syntax error with (zero based) "index" and (1 based) "number in line". I think this makes it easier to find the error when counting for the wrong character in the input string. But it requires a lot of tests to be updated.

If you don't like it, I can also revert it again. But I think it makes the error messages easier to read.

stleary commented 7 months ago

What problem does this code solve? Some tokener parsing error messages are not sufficiently descriptive

Does the code still compile with Java6? Yes

Risks Low. It's possible that some users' unit tests may fail due to this change. I think the value of the new messages outweighs this risk.

Changes to the API? No, just changes to some parsing error messages.

Will this require a new release? No

Should the documentation be updated? No

Does it break the unit tests? No, there was no previous coverage for these errors. New tests were added.

Was any code refactored in this commit? No

Review status APPROVED

Starting 3-day comment window.