Uncaught exception when cache file is empty (i.e. invalid JSON)
See original GitHub issueTell us about your environment
- ESLint Version: 3.10.2
- Node Version: 6.9.1
What parser (default, Babel-ESLint, etc.) are you using? default
Please show your full configuration:
What did you do? Please include the actual source code causing the issue.
Reposting this issue:
Suddenly standard started giving the attached below output. After spending some time searching through my code and reducing it to 0 files I was still getting the same error. Later I’ve found that there is no try/catch trying to parse back the JSON from the cache files found at .standard-cache, so when the file is empty it crashes. The problem seems to be at flat-cache package or its usage, but I thought you may know more about it. I’ll try to take a deeper look, anyway.
What do you think about trying to delete cache files when this kind of error occurs?
Hope I can help in any manner 😃
So, basically the cache file parsing probably needs a try-catch. In case it’s relevant, here’s the place where we set the cache options: https://github.com/Flet/standard-engine/blob/b579ea143c8e64254caebbd276c1d67b16793458/index.js#L35-L36
What did you expect to happen?
No uncaught exceptions.
What actually happened? Please include the actual, raw output from ESLint.
SyntaxError: Unexpected end of JSON input
at Object.parse (native)
at Object.parseRecursion [as parse] (.../node_modules/circular-json/build/circular-json.node.js:182:15)
at module.exports.readJSON (.../node_modules/flat-cache/utils.js:15:25)
at Object.cache.load (.../node_modules/flat-cache/cache.js:25:23)
at Object.module.exports.create (.../node_modules/flat-cache/cache.js:158:9)
at Object.module.exports.load (.../node_modules/flat-cache/cache.js:144:17)
at Object.module.exports.create (.../node_modules/file-entry-cache/cache.js:13:27)
at new CLIEngine (.../node_modules/eslint/lib/cli-engine.js:463:38)
at .../node_modules/standard-engine/index.js:107:16
at .../node_modules/deglob/index.js:51:12
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:15 (13 by maintainers)
Top GitHub Comments
Right now, an uncaught exception is thrown (and the node process terminates) when the cache file is invalid. As a result, the same error occurs the next time ESLint is run, as @not-an-aardvark correctly pointed out.
The issue is in
flat-cache
on this line. They call a function that can throw exceptions but do not have atry
-catch
block to handle the case where the string is invalid JSON.I opened an issue on
flat-cache
to get the author’s thoughts: https://github.com/royriojas/flat-cache/issues/12IMO, the correct behavior is to invalidate the cache if it’s unusable.
Yes, as far as I can tell, it should be safe to publish the changes in https://github.com/royriojas/flat-cache/pull/13 in a new patch version.