Skip to content

fix(opencode): extract nested error message from API responses#22239

Closed
Ricardo-M-L wants to merge 1 commit intoanomalyco:devfrom
Ricardo-M-L:fix/nested-error-message-extraction
Closed

fix(opencode): extract nested error message from API responses#22239
Ricardo-M-L wants to merge 1 commit intoanomalyco:devfrom
Ricardo-M-L:fix/nested-error-message-extraction

Conversation

@Ricardo-M-L
Copy link
Copy Markdown

Issue for this PR

Closes #22238

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Line 68 in error.ts uses body.message || body.error || body.error?.message to extract error messages from API responses. When body.error is an object (standard OpenAI/Anthropic format like { error: { message: "rate limit exceeded" } }), the || short-circuits on the truthy object and never reaches body.error?.message. The typeof errMsg === "string" check on line 69 then rejects the object, so no useful message is shown.

Fix: check typeof body.error === "string" before using it directly, otherwise fall through to body.error?.message.

How did you verify your code works?

Tested with mock API responses in both formats:

  • { error: "string error" } → correctly returns "string error"
  • { error: { message: "rate limit exceeded" } } → correctly returns "rate limit exceeded"
  • { message: "direct message" } → still works as before

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@rekram1-node
Copy link
Copy Markdown
Collaborator

denounce

opencode-agent bot pushed a commit that referenced this pull request Apr 13, 2026
mrsimpson pushed a commit to mrsimpson/opencode that referenced this pull request Apr 14, 2026
@Ricardo-M-L
Copy link
Copy Markdown
Author

Understood, closing this PR. Thanks for the review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: nested error message from API response is not extracted correctly

2 participants