Repository navigation
Conversation
parse_message's user, assistant, result and rate_limit_event branches caught only KeyError, but a present-yet-non-dict nested payload (message, deferred_tool_use, rate_limit_info) fails at subscripting with TypeError first, so the raw exception escaped the documented MessageParseError contract and callers catching ClaudeSDKError missed it. Add a TypeError handler to each branch that raises MessageParseError with the offending frame in .data, following the anthropics#1058 precedent for the sibling content-shape case. Fixes anthropics#1508
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #1508.
parse_message's user, assistant, result and rate_limit_event branches catch onlyKeyError, but a present-yet-non-dict nested payload (message,deferred_tool_use,rate_limit_info) fails at subscripting withTypeErrorfirst — so the raw exception escaped the documentedMessageParseErrorcontract (docstring :60-61) and callers catchingClaudeSDKErrormissed it, killing the message stream without a.datapayload.Each of the four branches gets its own
except TypeErrorhandler raisingMessageParseError("Invalid nested payload in ...", data), following the #1058 precedent for the sibling content-shape case. Missing-field handling is untouched.Test plan
test_non_dict_nested_payloads_raise_message_parse_error: 9 malformed frames (string/list/Nonemessage, truthy non-dictdeferred_tool_use, string/Nonerate_limit_info) all raiseMessageParseErrorwith "Invalid nested payload", catchable asClaudeSDKErrorand carrying the frame in.data.main(rawTypeError) and passes with the fix.pytest tests/: 1756 passed, 6 skipped.ruff check,mypy src/ scripts/clean.