-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
Exception line #301
Comments
With issue #244, the exceptions will be overworked and parse errors will be annotated with a byte count to indicate the error location. |
Parse errors will be thrown as
|
I am new to this library, but so far it works great. Thanks for your good work! Just one question: I really need this feature, we need to know where in the input file the error was. How can I use this new feature, or when will it be released to the main branch? |
@haimat This feature is planned for the 3.0.0 release - as introducing new exceptions means a change in the public API, we cannot release it to the 2.x.x track. In the meantime, you can check out the feature branch for this feature. It implements the described feature, but may change in the future when we merge it into the develop branch. I would look forward to hearing of your experiences. |
@nlohmann Thank you very much for the quick response. I have tested this new feature and it definitely is an improvement! However, having only the byte number in the stream without knowing the context where (i.e. in which line) the error is within the file is a bit hard to read. Any chance you will implement a translation from byte number to line/column? |
@haimat I'm not sure how much effort this is, because the lexer skips all whitespace. To track a line/column count, this code needs to be adapted. I shall have a look at this, but other issues have priority. |
@nlohmann Does that mean the indicated byte-position is calculated after stripping away the whitespaces? In that case I am afraid it does not help at all, because then I could never match it against the original file :( |
@haimat No, it is the exact byte count, including whitespace. |
This issue is nearly complete. If anyone would like to have a look at the soon-to-be-merged state, please have a look at branch https://github.com/nlohmann/json/tree/feature/exceptions_3.0.0. It contains parse_error exceptions with a byte count to the error, and only the documentation needs some final touches. |
Merged this feature into |
Hello,
it's not an issue but since I found no place to post my question I put it here.
So my question is, is it possible to get the line where the exception was throw in the file ?
For exemple in this file:
{ "none" { "name": "holaaaaa" } }
I would like the exception to return 2 for exemple.
Thanks.
The text was updated successfully, but these errors were encountered: