Skip to content

Commit

Permalink
Catch and ignore errors writing JSON files.
Browse files Browse the repository at this point in the history
This is an alternative attempt at fixing issue #3215, given the
complexity of PR #3239.
  • Loading branch information
Guido van Rossum committed Apr 30, 2017
1 parent 8293f40 commit a12432d
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions mypy/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -897,12 +897,17 @@ def write_cache(id: str, path: str, tree: MypyFile,
data_mtime = os.path.getmtime(data_json)
manager.trace("Interface for {} is unchanged".format(id))
else:
with open(data_json_tmp, 'w') as f:
f.write(data_str)
f.write('\n')
data_mtime = os.path.getmtime(data_json_tmp)
os.replace(data_json_tmp, data_json)
manager.trace("Interface for {} has changed".format(id))
try:
with open(data_json_tmp, 'w') as f:
f.write(data_str)
f.write('\n')
os.replace(data_json_tmp, data_json)
data_mtime = os.path.getmtime(data_json)
except os.error as err:
# Most likely the error is the replace() call
# (see https://github.com/python/mypy/issues/3215).
manager.log("Error writing data JSON file {}".format(data_json_tmp))

mtime = st.st_mtime
size = st.st_size
Expand All @@ -922,12 +927,17 @@ def write_cache(id: str, path: str, tree: MypyFile,
}

# Write meta cache file
with open(meta_json_tmp, 'w') as f:
if manager.options.debug_cache:
json.dump(meta, f, indent=2, sort_keys=True)
else:
json.dump(meta, f)
os.replace(meta_json_tmp, meta_json)
try:
with open(meta_json_tmp, 'w') as f:
if manager.options.debug_cache:
json.dump(meta, f, indent=2, sort_keys=True)
else:
json.dump(meta, f)
os.replace(meta_json_tmp, meta_json)
except os.error as err:
# Most likely the error is the replace() call
# (see https://github.com/python/mypy/issues/3215).
manager.log("Error writing meta JSON file {}".format(meta_json_tmp))

return interface_hash

Expand Down

0 comments on commit a12432d

Please sign in to comment.