Repository navigation
Raise on error results in the Claude Agent SDK samples - #411
Open
byhashdong wants to merge 1 commit into
Open
byhashdong wants to merge 1 commit into
byhashdong wants to merge 1 commit into
Conversation
The samples returned ResultMessage.result without checking is_error, so a turn that failed (for example on a bad API key) completed the Workflow with the error text as its result.
|
|
brianstrauch
enabled auto-merge (squash)
November 12, 2026 18:33
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.
The Claude samples take
ResultMessage.resultas the answer without looking atis_error. Claude Code still ends a failed turn with aResultMessage, so with a bad API keyHooksWorkflowcompletes with"Invalid API key · Fix external API key"as its result, andstructured_outputfails with "returned no structured output", which doesn't say why. I hit this with a truncated key.This checks
is_errorin each sample and raises anApplicationErrorwith the reason. Intools,plugin_with_custom_transportandagent_chatit also replaces returning theerrorstext (e.g. after max turns) as if it were the answer. Inagent_chatthe update fails andreply_idkeeps pointing at the last good reply.For the test,
offline.pycan now return an API error. It also setsCLAUDE_CODE_MAX_RETRIES=0, otherwise Claude Code retries the 401 with backoff for a long time.api_error_test.pyruns each sample against a rejected key; before the change 9 of the 10 cases finished successfully.