Repository navigation
fix: make CLI JSON decode errors pickleable - #1489
Nandaninaulaa wants to merge 1 commit into
Conversation
mangeshraut712
left a comment
There was a problem hiding this comment.
The __reduce__ arguments match the constructor, and the pickle plus copy.copy test is the right regression for a multiprocessing boundary. Two follow-ups: deepcopy is untested, and sibling errors with a custom __init__ still have the same problem.
| self.original_error = original_error | ||
| super().__init__(f"Failed to decode JSON: {line[:100]}...") | ||
|
|
||
| def __reduce__(self) -> tuple[Any, tuple[str, Exception]]: |
There was a problem hiding this comment.
copy.copy uses this, but the test never runs copy.deepcopy. Worth adding, since a worker may clone the error that way. Also, MessageParseError.__init__(message, data) and ProcessError.__init__(message, exit_code, stderr) will still fail to unpickle with TypeError / a dropped constructor argument for the same reason CLIJSONDecodeError did. If those can also cross a process boundary, they need the same __reduce__ (or a shared helper on ClaudeSDKError). I'd either add them in this PR or note them as a follow-up so they are not forgotten.
Summary
Closes #1394.
Testing
python -m pytest tests/test_errors.py -q(10 passed)