jaredwray / flat-cache

A stupidly simple key/value storage using files to persist the data
MIT License
165 stars 30 forks source link

Uncaught exception when cache file contains invalid JSON #12

Closed feross closed 7 years ago

feross commented 7 years ago

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 (https://github.com/eslint/eslint/issues/7748) and standard (https://github.com/feross/standard/issues/673). More details in the linked issues.

royriojas commented 7 years ago

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

royriojas commented 7 years ago

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

feross commented 7 years ago

@royriojas Excellent, thanks!