Skip to content

fix: write execution file in finally block so rate limit errors are parseable#1146

Open
hashwnath wants to merge 1 commit intoanthropics:mainfrom
hashwnath:fix/1040-execution-file-finally-block
Open

fix: write execution file in finally block so rate limit errors are parseable#1146
hashwnath wants to merge 1 commit intoanthropics:mainfrom
hashwnath:fix/1040-execution-file-finally-block

Conversation

@hashwnath
Copy link
Copy Markdown

Fixes #1040

Problem

When the Claude Code SDK throws (e.g. rate limit, crash), the execution file is never written because the catch block in run-claude-sdk.ts re-throws immediately, making the writeFile call on the subsequent lines unreachable.

This means workflows using continue-on-error: true cannot inspect the collected messages to distinguish rate limits from other failures — both surface as exit code 1 with a generic SDK stack trace, and the execution_file output is empty.

Solution

Instead of re-throwing immediately in the catch block, the SDK error is stored in a variable. The execution file write proceeds (guarded by messages.length > 0 to avoid writing empty files), and only then is the error re-thrown.

This ensures:

  • The execution_file output is always populated when messages were collected, regardless of whether the SDK completed successfully
  • Callers can parse the execution file to detect rate_limit_event messages vs other failures
  • The error is still propagated with the same message format
  • No behavioral change for the success path

Changes

  • base-action/src/run-claude-sdk.ts: Store SDK error instead of immediately re-throwing; write execution file before propagating the error

Testing

  • All 653 existing tests pass
  • TypeScript type checking passes
  • Prettier formatting passes

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

Write execution file in finally block so rate limit errors are parseable

1 participant