Skip to content
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

Return position in parse error exceptions #503

Closed
qwertymodo opened this issue Mar 13, 2017 · 3 comments
Closed

Return position in parse error exceptions #503

qwertymodo opened this issue Mar 13, 2017 · 3 comments
Labels
solution: duplicate the issue is a duplicate; refer to the linked issue instead

Comments

@qwertymodo
Copy link

When a parsing error is encountered, an exception is thrown from parser::expect() indicating the expected token, but not the current parsing position, making it difficult to track down the offending syntax error. It would be nice if the current position (in line and column, if possible) could also be included in the error message.

@nlohmann
Copy link
Owner

This is solved with #301 and will be part of the 3.0.0 release. Parse errors are now indicated with a user-defined exception json::parse_error which has a public member

/*!
@brief byte index of the parse error

The byte index of the last read character in the input file.

@note For an input with n bytes, 1 is the index of the first character
      and n+1 is the index of the terminating null byte or the end of
      file. This also holds true when reading a byte vector (CBOR or
      MessagePack).
*/
const size_t byte;

You can try the code in the develop branch (note this is unreleased code that is subject to change!).

@nlohmann nlohmann added the solution: duplicate the issue is a duplicate; refer to the linked issue instead label Mar 13, 2017
@qwertymodo
Copy link
Author

Sorry for the duplicate, I apparently neglected to search through the closed list. Looks good, thanks!

@nlohmann
Copy link
Owner

No worries. I just merged it to develop yesterday and did not add it to the online documentation. I would be happy to hear about your experience with that.

(Once again, please note that this feature will not be "official" until 3.0.0 is released and may change until then!)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
solution: duplicate the issue is a duplicate; refer to the linked issue instead
Projects
None yet
Development

No branches or pull requests

2 participants