Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion distributed/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1690,6 +1690,10 @@ def error_message(e: BaseException, status: str = "error") -> ErrorMessage:
}


class UnreadablePickledException(Exception):
pass


def clean_exception(
exception: BaseException | bytes | bytearray | str | None,
traceback: types.TracebackType | bytes | str | None = None,
Expand All @@ -1707,7 +1711,7 @@ def clean_exception(
try:
exception = protocol.pickle.loads(exception)
except Exception:
exception = Exception(exception)
exception = UnreadablePickledException(exception)
elif isinstance(exception, str):
exception = Exception(exception)

Expand Down
11 changes: 11 additions & 0 deletions distributed/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
RPCClosed,
Server,
Status,
UnreadablePickledException,
_expects_comm,
clean_exception,
coerce_to_address,
Expand Down Expand Up @@ -1357,3 +1358,13 @@ async def test_large_payload(caplog):

assert response["result"] == data
await comm.close()


@gen_test()
async def test_unreadable_pickled_exceptions_kept():
pickled_ex = b"\x80\x04\x954\x00\x00\x00\x00\x00\x00\x00\x8c\x08__main__\x94\x8c\x14SomeUnknownException\x94\x93\x94\x8c\x08some arg\x94\x85\x94R\x94."
ex_type, ex, tb = clean_exception(pickled_ex)
assert ex_type == UnreadablePickledException
assert isinstance(ex, UnreadablePickledException)
assert ex.args[0] == pickled_ex
assert tb is None
Loading