diff --git a/chatmaild/src/chatmaild/filedict.py b/chatmaild/src/chatmaild/filedict.py index bfcf42e9..006fa73a 100644 --- a/chatmaild/src/chatmaild/filedict.py +++ b/chatmaild/src/chatmaild/filedict.py @@ -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 {} diff --git a/chatmaild/src/chatmaild/tests/test_filedict.py b/chatmaild/src/chatmaild/tests/test_filedict.py index 0f585349..81802cda 100644 --- a/chatmaild/src/chatmaild/tests/test_filedict.py +++ b/chatmaild/src/chatmaild/tests/test_filedict.py @@ -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