Skip to content

Exception line #301

Closed
Closed

Description

@lucassardois

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.

Activity

  1. added this to the Release 3.0.0 milestone on Aug 27, 2016
  2. nlohmann commented on Aug 29, 2016

    @nlohmann
    Owner

    With issue #244, the exceptions will be overworked and parse errors will be annotated with a byte count to indicate the error location.

  3. added a commit that references this issue on Nov 14, 2016
  4. nlohmann commented on Nov 14, 2016

    @nlohmann
    Owner

    Parse errors will be thrown as json::parse_error exception which have a public member byte indicating the byte count to indicate the error location. Error messages look like this:

    [json.exception.parse_error.101] parse error at 7: unexpected end of input; expected ':'
    
  5. self-assigned this
    on Nov 16, 2016
  6. haimat commented on Dec 11, 2016

    @haimat

    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?

  7. nlohmann commented on Dec 11, 2016

    @nlohmann
    Owner

    @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.

  8. haimat commented on Dec 11, 2016

    @haimat

    @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?

  9. nlohmann commented on Dec 12, 2016

    @nlohmann
    Owner

    @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.

  10. haimat commented on Dec 12, 2016

    @haimat

    @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 :(

  11. nlohmann commented on Dec 12, 2016

    @nlohmann
    Owner

    @haimat No, it is the exact byte count, including whitespace.

  12. nlohmann commented on Mar 8, 2017

    @nlohmann
    Owner

    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.

  13. added
    solution: proposed fixa fix for the issue has been proposed and waits for confirmation
    and removed
    solution: proposed fixa fix for the issue has been proposed and waits for confirmation
    on Mar 12, 2017
  14. nlohmann commented on Mar 12, 2017

    @nlohmann
    Owner

    Merged this feature into develop. All there is left to do is to document the changes between old and new exceptions in the wiki page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions