Skip to content

Commit

Permalink
fix: try/except news.json load
Browse files Browse the repository at this point in the history
This would be in the off chance the json is malformed.
  • Loading branch information
tazlin committed Jun 5, 2024
1 parent db3d8c4 commit 30fed4a
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion horde/classes/base/news.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,14 @@ def __init__(self):

if os.path.exists(path):
with open(path) as file:
self.HORDE_NEWS = json.load(file)
try:
self.HORDE_NEWS = json.load(file)
except json.JSONDecodeError:
self.HORDE_NEWS = []
logger.error(f"File {path} is not a valid JSON file. No news will be available.")
except Exception as e:
self.HORDE_NEWS = []
logger.exception(f"An error occurred while reading the news file: {e}")
else:
self.HORDE_NEWS = []
logger.error(f"File {path} not found. No news will be available.")
Expand Down

0 comments on commit 30fed4a

Please sign in to comment.