Skip to content

Commit

Permalink
catch exceptions when trying to parse selection_group cache file
Browse files Browse the repository at this point in the history
  • Loading branch information
TitanNano committed Nov 5, 2022
1 parent 8e48b3f commit 9560a54
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/control_any_sim/services/selection_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,24 +57,25 @@ def get_instance(cls, household_id):
# restore state
try:
file_handler = open(HOME_DIR + '/selection_group.json', encoding="utf8")
state = file_handler.read()
file_handler.close()
Logger.log(f'restored state: {state}')
except BaseException:
file_handler = None
state = None

if file_handler is None or not file_handler.readable():
if state is None:
return cls(household_id)

state = file_handler.read()
file_handler.close()

Logger.log(f'restored state: {state}')

# deserialize
instance = cls.deserialize(state) # pylint: disable=no-member
try:
instance = cls.deserialize(state) # pylint: disable=no-member

if instance.household_id != household_id:
return cls(household_id)
if instance.household_id != household_id:
return cls(household_id)

return instance
return instance
except BaseException:
return cls(household_id)

@property
def client(self):
Expand Down

0 comments on commit 9560a54

Please sign in to comment.