Skip to content

Commit

Permalink
Fix json files corruptions
Browse files Browse the repository at this point in the history
  • Loading branch information
NastuzziSamy authored and gornostal committed Feb 7, 2021
1 parent 82af98f commit ea06bc9
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions ulauncher/utils/db/KeyValueJsonDb.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ def open(self) -> 'KeyValueJsonDb':
if not os.path.isfile(self._name):
raise IOError("%s exists and is not a file" % self._name)

with open(self._name, 'r') as _in:
self.set_records(json.load(_in))
try:
with open(self._name, 'r') as _in:
self.set_records(json.load(_in))
except json.JSONDecodeError:
# file corrupted, reset it.
self.commit()
else:
# make sure path exists
mkpath(os.path.dirname(self._name))
Expand Down

0 comments on commit ea06bc9

Please sign in to comment.