fix: prevent crash when message.content is undefined in Anthropic API calls #10954
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.
Fixes the "Cannot read properties of undefined (reading 'filter')" error reported in Reddit.
Problem
Users were experiencing API request failures when using Anthropic Claude models with the error:
The error occurred in
filterNonAnthropicBlocks()when attempting to filter message content that wasundefined,null, or not an array.Solution
Added a guard clause in
filterNonAnthropicBlocks()to check ifmessage.contentis:undefinednullIf any of these conditions are true, the message is filtered out gracefully rather than causing a crash.
Changes
filterNonAnthropicBlocks()Testing
All tests pass (13/13) including 4 new tests for edge cases.
View task on Roo Code Cloud
Important
Adds a guard clause in
filterNonAnthropicBlocks()to handleundefined,null, or non-arraymessage.content, preventing crashes and adding tests for these cases.filterNonAnthropicBlocks()inanthropic-filter.tsto handleundefined,null, or non-arraymessage.content.anthropic-filter.spec.tsfor edge cases:undefined,null, non-array, and empty array content.This description was created by
for 33687d9. You can customize this summary. It will automatically update as commits are pushed.