Ver código fonte

catch exceptions when migrating storage files (fixes #2276)

Falko Schindler 1 ano atrás
pai
commit
7b94a1cba9
1 arquivos alterados com 5 adições e 1 exclusões
  1. 5 1
      nicegui/storage.py

+ 5 - 1
nicegui/storage.py

@@ -156,6 +156,10 @@ class Storage:
         """
         for filepath in self.path.glob('storage_*.json'):
             new_filepath = filepath.with_stem(filepath.stem.replace('_', '-'))
-            data = json.loads(filepath.read_text())
+            try:
+                data = json.loads(filepath.read_text())
+            except Exception:
+                log.warning(f'Could not load storage file {filepath}')
+                data = {}
             filepath.rename(new_filepath)
             new_filepath.write_text(json.dumps(data), encoding='utf-8')