Skip to content

Commit

Permalink
🥅 Handle empty or corrupted existing correlations.json
Browse files Browse the repository at this point in the history
  • Loading branch information
shnizzedy committed Nov 6, 2024
1 parent b0982b4 commit 82764c9
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion cpac_correlations/cpac_correlations.py
Original file line number Diff line number Diff line change
Expand Up @@ -1171,7 +1171,12 @@ def compare_pipelines(

if correlations_json_path.exists():
with correlations_json_path.open("r", encoding="utf8") as json_file:
correlations_json = [*json.load(json_file), *correlations_json]
_loaded_json: list[dict[str, str]] = []
try:
_loaded_json = json.load(json_file)
except json.decoder.JSONDecodeError:
pass # empty or corrupted file
correlations_json = [*_loaded_json, *correlations_json]
with correlations_json_path.open("w", encoding="utf8") as json_file:
try:
flock(json_file.fileno(), LOCK_EX) # Lock the file
Expand Down

0 comments on commit 82764c9

Please sign in to comment.