Explorar o código

handle issues with broken json etc

Rodja Trappe hai 1 ano
pai
achega
88045e1e6b
Modificáronse 1 ficheiros con 4 adicións e 1 borrados
  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:
     def __init__(self, filepath: Path) -> None:
         self.filepath = filepath
         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)
         super().__init__(data, on_change=self.backup)
 
 
     def backup(self) -> None:
     def backup(self) -> None: