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

The parse exception clues are off sometimes #15

Open
etiktin opened this issue Sep 24, 2015 · 2 comments
Open

The parse exception clues are off sometimes #15

etiktin opened this issue Sep 24, 2015 · 2 comments

Comments

@etiktin
Copy link

etiktin commented Sep 24, 2015

I'm using jju to provide more helpful errors when parsing invalid JSON files. I noticed that sometimes the clues about the location of the error (line:column) are off and it seems it mostly adds 1 to either the line or the column.
Here's an example of the column index being off:

var jju = require('jju');
jju.parse('{"a":1,\n"b":{"ba":"foo"\n}', {mode: 'json'});

When I run it I get:

Unexpected end of input at 3:3
}
 ^

The end of input is at 3:2 and not 3:3. Am I missing something?

@rlidwka
Copy link
Owner

rlidwka commented Sep 26, 2015

When the error is occured, current caret position is at 3:3. So parser expects something at 3:3, but can't find anything.

I don't think this one is misleading, an end of input is an end of input. Are there any other similar cases?

@etiktin
Copy link
Author

etiktin commented Sep 26, 2015

Why is the caret at 3:3? The string ends with '}' which is located at 3:1 so I expect the end of input to be at 3:2. Also if you look at the output the ^ is pointing to the next character after '}' so that also seems to suggest the location should be 3:2.

Here's another case that I find a bit confusing, when you parse this:

{
    "a": "b",
    "c": 5,
}

You get:

Trailing comma in object at 4:1
}
^

The trailing comma is at the end of the third line and not at the beginning of the fourth line. In this case I understand the index, since 4:1 is the point where the parse actually failed. That said, I find it confusing that we say the issue is a "Trailing comma in object at", but instead of telling the user where that comma is located, we give the index of the closing curly brace. If you add some extra new lines before the closing brace the index would change accordingly, even due the actual problem, the trailing comma, is at the same location.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants