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

Uncaught exception when cache file contains invalid JSON #12

Closed
feross opened this issue Dec 17, 2016 · 3 comments
Closed

Uncaught exception when cache file contains invalid JSON #12

feross opened this issue Dec 17, 2016 · 3 comments

Comments

@feross
Copy link

feross commented Dec 17, 2016

When you call readJSON() on this line, there is a chance that an exception will be thrown, since JSON.parse() is called under-the-hood.

JSON.parse() calls should be wrapped in a try-catch block in case the string can't be parsed as JSON. This can happen if another program creates/modifies the cache file, or if the node script using flat-cache crashes in the middle of a write.

This issue is currently affecting ESLint (eslint/eslint#7748) and standard (standard/standard#673). More details in the linked issues.

@royriojas
Copy link
Contributor

Hi @feross, thanks for reporting it, will take a look.

royriojas added a commit that referenced this issue Dec 19, 2016
Fixes #12

Not sure under which situations a cache file might exist that does
not contain a valid JSON structure, but just in case to cover
the possibility of this happening a try catch block has been added

If the cache is somehow not valid the cache will be discarded an a
a new cache will be stored instead
royriojas added a commit that referenced this issue Dec 20, 2016
Fixes #12

Not sure under which situations a cache file might exist that does
not contain a valid JSON structure, but just in case to cover
the possibility of this happening a try catch block has been added

If the cache is somehow not valid the cache will be discarded an a
a new cache will be stored instead
@royriojas
Copy link
Contributor

Hi @feross, a new patch version was published, should fix the issue in Eslint.

@feross
Copy link
Author

feross commented Dec 24, 2016

@royriojas Excellent, thanks!

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