more resilience

This commit is contained in:
holger krekel 2024-03-27 18:13:21 +01:00
parent 76512dfa2d
commit f5dc4cb71e
2 changed files with 10 additions and 0 deletions

View File

@ -35,3 +35,6 @@ class FileDict:
return marshal.load(f)
except FileNotFoundError:
return {}
except Exception:
logging.warning("corrupt marshal data at: %r", self.path)
return {}

View File

@ -22,3 +22,10 @@ def test_dying_lock(tmp_path, caplog):
d["1"] = "3"
assert fdict1.read()["1"] == "3"
assert fdict2.read()["1"] == "3"
def test_bad_marshal_file(tmp_path, caplog):
fdict1 = FileDict(tmp_path.joinpath("metadata"))
fdict1.path.write_bytes(b"l12k3l12k3l")
assert fdict1.read() == {}
assert "corrupt" in caplog.records[0].msg