question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Uncaught exception when cache file is empty (i.e. invalid JSON)

See original GitHub issue

Tell 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:

standard 8.6.0

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

cc @alvaropinot @VzqzAc

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:15 (13 by maintainers)

github_iconTop GitHub Comments

3reactions
ferosscommented, Dec 17, 2016

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 a try-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/12

IMO, the correct behavior is to invalidate the cache if it’s unusable.

2reactions
not-an-aardvarkcommented, Dec 19, 2016

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

SyntaxError: Unexpected token < in JSON at position 0
Since it looks like the error seems to have something to do with pulling JSON data from the server, I tried starting from...
Read more >
6 Fixes for "the response is not a valid JSON response" Error in
1. Reset the permalinks ... Before you try anything else, you should try resetting your permalinks to resolve the invalid JSON response error....
Read more >
How to Fix a 400 Bad Request Error (Causes and Fixes) - Kinsta
1. Check the Submitted URL · 2. Clear Browser Cache · 3. Clear Browser Cookies · 4. File Upload Exceeds Server Limit ·...
Read more >
Caching - 4.x - CakePHP Cookbook
File File cache is a simple cache that uses local files. It is the slowest cache engine, and doesn't provide as many features...
Read more >
How to Clear Your Browser Cache - Fort Valley State University
Make sure there's a check mark next to “Cookies, Site Data,” and “Cached Images and Files.” Tap Clear browsing data. Internet Explorer clear...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found