Browse Source

handle issues with broken json etc

Rodja Trappe 1 year ago
parent
commit
88045e1e6b
1 changed files with 4 additions and 1 deletions
  1. 4 1
      nicegui/storage.py

+ 4 - 1
nicegui/storage.py

@@ -43,7 +43,10 @@ class PersistentDict(observables.ObservableDict):
 
     def __init__(self, filepath: Path) -> None:
         self.filepath = filepath
-        data = json.loads(filepath.read_text()) if filepath.exists() else {}
+        try:
+            data = json.loads(filepath.read_text()) if filepath.exists() else {}
+        except Exception:
+            data = {}
         super().__init__(data, on_change=self.backup)
 
     def backup(self) -> None: