fix: add forward compatibility for unknown message types#593
Open
dotuananh0712 wants to merge 1 commit intoanthropics:mainfrom
Open
fix: add forward compatibility for unknown message types#593dotuananh0712 wants to merge 1 commit intoanthropics:mainfrom
dotuananh0712 wants to merge 1 commit intoanthropics:mainfrom
Conversation
Skip unknown message types with a warning log instead of crashing. This makes the SDK resilient against future CLI updates.
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
Add forward compatibility for unknown message types by catching
MessageParseErrorin the message loop and logging a warning instead of crashing. This makes the SDK resilient against future CLI updates without requiring code changes.Changes
client.py: Wrap
parse_message()call in try-except that catchesMessageParseErrorand logs a warning, then continues processing messages.Problem
Previously, any unknown message type from the CLI would raise
MessageParseErrorand crash the SDK. This made the SDK fragile against CLI updates - any new message type would break existing integrations.Solution
Instead of crashing on unknown message types, the SDK now:
MessageParseErrorwhen parsing failsThis approach ensures the SDK gracefully handles any future unknown message types from the CLI.
Part 2 of 2 (see also: #589)