Skip to content

Commit 79ab2d4

Browse files
committed
Catch msgspec DecodeError by name when reading corrupt store files
1 parent e7e0f18 commit 79ab2d4

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

dash/_shared_storage/_codec.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111

1212
import msgspec
1313

14+
# msgspec raises this on malformed input. It subclasses ``ValueError`` in
15+
# current msgspec but not in every version, so callers should catch it by name.
16+
DecodeError = msgspec.DecodeError
17+
1418
_encoder = msgspec.msgpack.Encoder()
1519
_decoder = msgspec.msgpack.Decoder()
1620

dash/_shared_storage/_persistence.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,9 @@ def _read(path: str) -> Optional[Any]:
107107
try:
108108
with open(path, "rb") as f:
109109
return _codec.decode(f.read())
110-
except (OSError, ValueError):
111-
# OSError -> missing/unreadable; ValueError -> msgspec DecodeError.
110+
except (OSError, ValueError, _codec.DecodeError):
111+
# OSError -> missing/unreadable; DecodeError -> corrupt msgpack
112+
# (caught by name since it does not subclass ValueError everywhere).
112113
return None
113114

114115
def _write_chunk(self, chunk_num: int) -> None:

0 commit comments

Comments
 (0)