Skip to content

Commit

Permalink
handle when file read operation fails
Browse files Browse the repository at this point in the history
  • Loading branch information
martinmiglio committed Dec 9, 2023
1 parent dbcc827 commit dcddac1
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/pyclashbot/utils/caching.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
A module to cache and load program data to and from the disk
"""
from io import UnsupportedOperation
import json
import pickle
from os import makedirs, remove
Expand Down Expand Up @@ -32,7 +33,7 @@ def cache_data(self, data):
with open(file_path, "w", encoding="utf-8") as this_file:
try:
file_data = json.load(this_file)
except json.JSONDecodeError:
except (json.JSONDecodeError, UnsupportedOperation):
file_data = {}
file_data |= data
json.dump(file_data, this_file, indent=4)
Expand All @@ -47,7 +48,7 @@ def load_data(self):
with open(file_path, "r", encoding="utf-8") as this_file:
try:
return json.load(this_file)
except json.JSONDecodeError:
except (json.JSONDecodeError, UnsupportedOperation):
return {}

def exists(self) -> bool:
Expand Down

0 comments on commit dcddac1

Please sign in to comment.