-
Notifications
You must be signed in to change notification settings - Fork 0
fix: anthropic error catching #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
""" WalkthroughError message formatting is centralized by adding a new abstract protected method Changes
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (7)
🚧 Files skipped from review as they are similar to previous changes (1)
🧰 Additional context used🧬 Code Graph Analysis (6)src/Agents/Adapter.php (5)
src/Agents/Adapters/Gemini.php (5)
src/Agents/Adapters/Perplexity.php (6)
src/Agents/Adapters/Deepseek.php (5)
src/Agents/Adapters/OpenAI.php (5)
src/Agents/Adapters/XAI.php (3)
🔇 Additional comments (12)
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR centralizes error formatting across all agent adapters and enhances streamed response processing by standardizing how chunks and errors are handled.
- Introduces an abstract
formatErrorMessagemethod in the baseAdapterclass and implements it in each adapter. - Updates each adapter’s
processand HTTP status check logic to use the new unified formatter. - Improves stream parsing by handling optional
"data: "prefixes and non-stream error responses.
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/Agents/Adapters/XAI.php | Added chunk processing with unified error formatting via formatErrorMessage. |
| src/Agents/Adapters/Perplexity.php | Swapped in formatErrorMessage call for error cases (implementation missing). |
| src/Agents/Adapters/OpenAI.php | Added HTTP status check, throws formatted exception, and implemented formatErrorMessage. |
| src/Agents/Adapters/Gemini.php | Refactored error handling to delegate to formatErrorMessage. |
| src/Agents/Adapters/Deepseek.php | Replaced inline error formatting with formatErrorMessage. |
| src/Agents/Adapters/Anthropic.php | Enhanced non-stream error capture, unified prefix stripping, and added formatter. |
| src/Agents/Adapter.php | Declares abstract protected function formatErrorMessage($json): string;. |
Comments suppressed due to low confidence (3)
src/Agents/Adapters/Perplexity.php:121
- The Perplexity adapter now calls
formatErrorMessage($json)but does not implement this method, leading to a fatal error. Add a protectedformatErrorMessage($json): stringimplementation to Perplexity.php or inherit a default.
if (is_array($json) && isset($json['error'])) {
src/Agents/Adapters/Anthropic.php:222
- The variable
$payloadis not defined in this scope, which will cause an undefined variable error. Ensure the stream flag is retrieved from a valid variable (e.g., method parameter or class property) or include$payloadin the closure's context.
if (! $payload['stream']) {
src/Agents/Adapter.php:102
- [nitpick] Multiple adapters implement very similar
formatErrorMessagelogic. Consider providing a default implementation in the baseAdapterclass and letting adapters override only when necessary to reduce duplication.
abstract protected function formatErrorMessage($json): string;
Summary by CodeRabbit