1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-04-15 08:40:34 +03:00

Made use of guard clauses where possible

This commit is contained in:
A_D 2021-06-04 16:26:07 +02:00
parent f9efe0e5a9
commit caf594752f
No known key found for this signature in database
GPG Key ID: 4BE9EB7DF45076C4

View File

@ -883,21 +883,27 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below
# said it's `Backpack.json`
backpack_file = pathlib.Path(str(self.currentdir)) / 'Backpack.json'
backpack_data = None
if backpack_file.exists():
backpack_data = backpack_file.read_bytes()
else:
if not backpack_file.exists():
logger.warning(f'Failed to find backpack.json file as it appears not to exist? {backpack_file=}')
else:
backpack_data = backpack_file.read_bytes()
parsed = None
if backpack_data is not None and len(backpack_data) > 0:
try:
parsed = json.loads(backpack_data)
except json.JSONDecodeError:
logger.exception('Unable to parse Backpack.json')
if backpack_data is None:
logger.warning('Unable to read backpack data!')
elif len(backpack_data) == 0:
logger.warning('Backpack.json was empty when we read it!')
else:
logger.warning('Unable to read backpack data! Either the file was empty or it didn\'t exist!')
try:
parsed = json.loads(backpack_data)
except json.JSONDecodeError:
logger.exception('Unable to parse Backpack.json')
if parsed is not None:
entry = parsed # set entry so that it ends up in plugins with the right data