fix: report api_error_status instead of "success" on API errors - #1158
Open
guptaishaan wants to merge 1 commit into
Open
fix: report api_error_status instead of "success" on API errors#1158guptaishaan wants to merge 1 commit into
guptaishaan wants to merge 1 commit into
Conversation
The CLI reports a failed API call as is_error=True with subtype
"success", an empty errors[], and the HTTP status in api_error_status.
The error text in _internal/query.py is built as
`"; ".join(errors) or str(subtype)`, so both branches fell through to
the subtype and callers were told:
Claude Code returned an error result: success
The only diagnostic in the frame, api_error_status, was dropped.
When errors[] is empty and api_error_status is set, use it, so the text
reads "API error (HTTP 400)". Frames carrying a non-empty errors[] are
unchanged.
This fixes the reporting only. It does not address the underlying 400,
which originates outside this package.
Fixes anthropics#1156
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.
Fixes #1156
Scope: this fixes the error reporting only. It does not stop the HTTP 400 the
reporter is hitting.
_internal/query.pybuilds the error text for a failing result as"; ".join(errors) or str(subtype). The CLI reports a failed API call asis_error=Truewithsubtype="success", an emptyerrors[], and the status inapi_error_status, so both branches fall through to the subtype and the calleris told
Claude Code returned an error result: success. The one useful field inthe frame is dropped.
We already document that wire shape in
types.py("HTTP status code of thefailing API call when
is_erroris True andsubtypeis 'success'"), so thisjust uses it: when
errors[]is empty andapi_error_statusis set, the errortext becomes
API error (HTTP 400)instead ofsuccess. Frames with anon-empty
errors[]are unchanged.Verified on Python 3.12.13, x86_64 Linux:
TestProcessExitAfterErrorResultfails before the change withActual message: 'Claude Code returned an error result: success'and passesafter.
are clean.
Not verified: I never saw the 400. I have no Max OAuth credential and made no
API calls, so the reproduction is a mock transport replaying the frame from the
issue. I also have no explanation for why
--printsucceeds while the streamingtransport gets a 400. Nothing in this package builds the API request, so that
question belongs in the CLI, and it stays open.
Thanks to @mattleahy1 for the report. The eliminations across CLI versions,
models and containers, and pointing straight at the
"; ".join(errors) or str(subtype)fallback, is what made this a one-line diagnosis.