fix: write execution file in finally block so rate limit errors are parseable#1146
Open
hashwnath wants to merge 1 commit intoanthropics:mainfrom
Open
fix: write execution file in finally block so rate limit errors are parseable#1146hashwnath wants to merge 1 commit intoanthropics:mainfrom
hashwnath wants to merge 1 commit intoanthropics:mainfrom
Conversation
…arseable When the SDK throws (e.g. rate limit, crash), the execution file write was unreachable because the catch block re-threw immediately. This meant callers using continue-on-error could not inspect the collected messages to distinguish rate limits from other failures. Store the SDK error, write the execution file (if any messages were collected), then re-throw. This ensures the execution_file output is always populated when messages exist, regardless of whether the SDK completed successfully. Fixes anthropics#1040
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 #1040
Problem
When the Claude Code SDK throws (e.g. rate limit, crash), the execution file is never written because the
catchblock inrun-claude-sdk.tsre-throws immediately, making thewriteFilecall on the subsequent lines unreachable.This means workflows using
continue-on-error: truecannot inspect the collected messages to distinguish rate limits from other failures — both surface as exit code 1 with a generic SDK stack trace, and theexecution_fileoutput is empty.Solution
Instead of re-throwing immediately in the
catchblock, the SDK error is stored in a variable. The execution file write proceeds (guarded bymessages.length > 0to avoid writing empty files), and only then is the error re-thrown.This ensures:
execution_fileoutput is always populated when messages were collected, regardless of whether the SDK completed successfullyrate_limit_eventmessages vs other failuresChanges
base-action/src/run-claude-sdk.ts: Store SDK error instead of immediately re-throwing; write execution file before propagating the errorTesting