Skip to content

Give better error message (and don't crash) if bad json in the cache #6277

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

Merged
merged 5 commits into from
Feb 7, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions mypy/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -825,8 +825,21 @@ def _load_json_file(file: str, manager: BuildManager,
manager.log(log_error + file)
return None
manager.trace(log_sucess + data.rstrip())
result = json.loads(data) # TODO: Errors
return result
try:
result = json.loads(data)
except ValueError: # TODO: JSONDecodeError in 3.5
manager.errors.set_file(file, None)
manager.errors.report(-1, -1,
"Error reading JSON file;"
" you likely have a bad cache.\n"
"Try removing the {cache_dir} directory"
" and run mypy again.".format(
cache_dir=manager.options.cache_dir
),
blocker=True)
return None
else:
return result


def _cache_dir_prefix(manager: BuildManager) -> str:
Expand Down