Skip to content

fix: make CLIJSONDecodeError survive pickle and copy - #1550

Open
shubhranillayek wants to merge 1 commit into
anthropics:mainfrom
shubhranillayek:fix/cli-json-decode-error-pickle
Open

shubhranillayek wants to merge 1 commit into
anthropics:mainfrom
shubhranillayek:fix/cli-json-decode-error-pickle

Conversation

@shubhranillayek

Copy link
Copy Markdown

Closes #1394

CLIJSONDecodeError could not be reconstructed by pickle or copy: e.args holds only the formatted message, so the default reconstruction calls type(e)(*e.args) and fails with TypeError: __init__() missing 1 required positional argument: 'original_error'. Across processes this takes down a ProcessPoolExecutor instead of surfacing the error.

This adds a __reduce__ that rebuilds the error from its original constructor args (line, original_error), keeping the message intact — making original_error optional the way ResultError does would not be enough here, since the reconstructed line would be the already-formatted message.

Also adds test_json_decode_error_survives_pickle_and_copy, mirroring the existing test_result_error_survives_pickle_and_copy.

Verified locally: the issue's pickle / copy.copy / ProcessPoolExecutor repros now surface the error instead of failing; pytest tests/test_errors.py 10 passed; full suite 1756 passed, 6 skipped; ruff check + ruff format --check and mypy on _errors.py are clean.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CLIJSONDecodeError cannot be pickled or copied, breaking ProcessPoolExecutor

1 participant