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

Diagnosing "Something is wrong with your metadata at position NaN and line 1" #17

Closed
wgoldie opened this issue Nov 1, 2018 · 3 comments

Comments

@wgoldie
Copy link
Contributor

wgoldie commented Nov 1, 2018

const position = parseInt(tokens[tokens.length - 1], 10);

This function doesn't appear to be portable - the error message that JSON.parse spits out isn't standardized.

In Chromium I get "Unexpected token a in JSON at position 175" which results in the correct behavior.

In Firefox I get "JSON.parse: expected double-quoted property name at line 37 column 30 of the JSON data". Here the attempt to extract the position fails.

@msfeldstein
Copy link
Owner

looks like we just need to update the pattern matching? I can look at this over the weekend probably, happy to accept pull requests as well

@wgoldie
Copy link
Contributor Author

wgoldie commented Nov 2, 2018

The issue is that JSON.parse can throw a SyntaxError with an arbitrary message. Different browsers/environments will have different error messages. I see a couple of options:

  1. We can try to identify the messages of different browser/runtime vendors and match against them, and fail gracefully otherwise. Unfortunately it seems that the useful SyntaxError.prototype.lineNumber property is not implemented by anyone besides Firefox (according to MDN)

  2. We could also use a library for JSON parsing that will reliably emit error locations. jsonlint seems like a good lightweight option.

Happy to write a PR on either of these tomorrow or over the weekend but I'm not sure which is better from your perspective.

@msfeldstein
Copy link
Owner

msfeldstein commented Nov 2, 2018 via email

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