Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow exceptions that fail pickle deserialisation to be easily identified downstream. #8882

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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