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

line breaks cause errors but can't tell which line #137

Closed
mtantawy opened this issue Feb 8, 2016 · 3 comments
Closed

line breaks cause errors but can't tell which line #137

mtantawy opened this issue Feb 8, 2016 · 3 comments

Comments

@mtantawy
Copy link

mtantawy commented Feb 8, 2016

Accidental line breaks within strings/values cause errors when trying to validate, analyze, or build which is expected.

The problem is the error fails to indicate the line responsible and instead shows ???

I was able to point the issue by checking the JSON on http://jsonlint.com/

@hacksalot
Copy link
Owner

Thanks for the report @mtantawy. As we are using the same library that jsonlint uses, we should be reporting identical line and column info. Will address for next release.

@hacksalot hacksalot added this to the v1.8.0 milestone Feb 9, 2016
@hacksalot
Copy link
Owner

Incidentally, this is a bit more involved than just catching an exception and reporting the line and column number. JSON.parse doesn't return that information consistently, neither do most other parsers. What HMR actually does is:

  1. Parse.
  2. Catch the exception.
  3. Re-parse with a syntax-error aware library.
  4. Since no single library currently catches all possibly syntax errors, re-parse with a second syntax-error-aware library if the first re-parse didn't pick up the line/column info.

Even then, there are edge cases -- yours is one of them -- where the column number won't be returned (and also isn't returned by, say, JSONLint.com). So for now it will be line + column for most syntax errors, but line-only for the embedded line break error specifically.

@mtantawy
Copy link
Author

Yeah at least showing the line number is better than nothing.
Appreciated the effort!

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

No branches or pull requests

2 participants