fix(provider): extract nested error.message from OpenAI-shaped bodies - #44057
fix(provider): extract nested error.message from OpenAI-shaped bodies#44057chandlerm923 wants to merge 1 commit into
Conversation
body.error is a truthy object for the common {"error":{"message":...}}
shape, so the old field order (body.message || body.error ||
body.error?.message) always short-circuited before reaching the nested
string, and the typeof guard then dropped it. Users saw the raw
response body or a generic status line instead of the real reason
(rate limit, quota, bad key).
— automated review (ox-alpha, round2) |
Issue for this PR
Closes #36410
Type of change
What does this PR do?
message()inpackages/opencode/src/provider/error.tsextracts a fallback error string from the response body with:For the common OpenAI-shaped body
{"error":{"message":"..."}},body.erroris a truthy object, so it wins the||chain beforebody.error.messageis ever read. Thetypeof errMsg === "string"check then fails and the real message is dropped — users see a generic status line or a raw JSON dump instead of the actual reason (rate limit, quota, invalid key, etc.).There was an earlier PR for this (#36411) that implemented essentially the same fix, but it went stale and was closed by the automated cleanup bot (>1 month old, no reactions) rather than rejected on the merits — no maintainer raised any objection to the approach there.
This PR reorders the extraction to type-check each field explicitly and prefer the nested string first:
How did you verify your code works?
packages/opencode/test/provider/error.test.ts: one for the nested{error:{message}}shape, one for the pre-existing top-level stringerrorshape (to make sure that path still works).bun test test/provider/error.test.ts— both new tests pass.bun turbo typecheck— 30/30 packages pass.Checklist