Skip to content

fix: report api_error_status instead of "success" on API errors - #1158

Open
guptaishaan wants to merge 1 commit into
anthropics:mainfrom
guptaishaan:fix-1156
Open

fix: report api_error_status instead of "success" on API errors#1158
guptaishaan wants to merge 1 commit into
anthropics:mainfrom
guptaishaan:fix-1156

Conversation

@guptaishaan

Copy link
Copy Markdown

Fixes #1156

Scope: this fixes the error reporting only. It does not stop the HTTP 400 the
reporter is hitting.

_internal/query.py builds the error text for a failing result as
"; ".join(errors) or str(subtype). The CLI reports a failed API call as
is_error=True with subtype="success", an empty errors[], and the status in
api_error_status, so both branches fall through to the subtype and the caller
is told Claude Code returned an error result: success. The one useful field in
the frame is dropped.

We already document that wire shape in types.py ("HTTP status code of the
failing API call when is_error is True and subtype is 'success'"), so this
just uses it: when errors[] is empty and api_error_status is set, the error
text becomes API error (HTTP 400) instead of success. Frames with a
non-empty errors[] are unchanged.

Verified on Python 3.12.13, x86_64 Linux:

  • New test in TestProcessExitAfterErrorResult fails before the change with
    Actual message: 'Claude Code returned an error result: success' and passes
    after.
  • Full suite: 1292 passed, 5 skipped. ruff check, ruff format --check and mypy
    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 --print succeeds while the streaming
transport 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.

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
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.

query() returns is_error with subtype="success" and api_error_status=400; --print succeeds with identical binary and credentials

1 participant