Explorar el Código

handle issues with broken json etc

Rodja Trappe hace 1 año
padre
commit
88045e1e6b
Se han modificado 1 ficheros con 4 adiciones y 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:
         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: