anthropics / anthropics/claude-code-action

Bug: `setupBranch()` calls `process.exit(1)`, bypassing top-level error handling, comment updates, and resource cleanup

オープン
#1,747 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る
bug p3
主要言語
TypeScript
スター
8.9k
フォーク
2.1k
PR マージ指標
PR 指標を取得中

説明

#### Description

In [`src/github/operations/branch.ts`](file:///src/github/operations/branch.ts), the `setupBranch()` function wraps its execution in a `try ... catch` block that logs the error and immediately invokes `process.exit(1)`:

```typescript
// src/github/operations/branch.ts:348-351
} catch (error) {
console.error("Error in branch setup:", error);
process.exit(1);
}
```

`setupBranch()` is called by `prepareTagMode()` during Phase 1 (Prepare) in the orchestrator [`src/entrypoints/run.ts`](file:///src/entrypoints/run.ts).

`run.ts` was designed to orchestrate the entire lifecycle inside a top-level `try ... catch ... finally` block:

- **`catch`**: Sets `prepareSuccess = false`, records `prepareError`, and reports `core.setFailed(...)`.
- **`finally`**:
1. Calls `workloadIdentity?.stop()` to delete temporary credentials.
2. Calls `updateCommentLink()` to update the tracking comment on GitHub with the actual error reason.
3. Writes step summaries and exposes outputs (`branch_name`, `github_token`) for downstream workflow cleanup steps (e.g. OIDC app token revocation).

Because `setupBranch()` invokes `process.exit(1)` directly:

1. The `catch` block in `run.ts` is never executed.
2. The `finally` block in `run.ts` is never executed.
3. The initial tracking comment posted to the issue/PR (e.g. `"Claude Code is working..."`) is never updated with failure details, leaving users with a permanently spinning/incomplete status.
4. Active background handles (like Workload Identity refresh timers) and post-action cleanup steps are bypassed.

#### Steps to Reproduce

1. Trigger the action in tag mode on an issue or PR where branch setup fails (e.g. triggering an invalid branch name from a template, an invalid base ref, or a git checkout conflict).
2. The branch setup error is logged to stdout, but the process exits immediately with code 1.
3. Observe that the GitHub issue/PR tracking comment is never updated to indicate failure, and remains in the pending "working..." state.

#### Expected Behavior

`setupBranch()` should rethrow the error (`throw error;`) rather than exiting the process, allowing `run.ts` to catch the failure, update the tracking comment with the error details, clean up tokens/handles in `finally`, and fail cleanly via `@actions/core`.

#### Proposed Fix

In [`src/github/operations/branch.ts`](file:///src/github/operations/branch.ts):

```diff
} catch (error) {
console.error("Error in branch setup:", error);
- process.exit(1);
+ throw error;
}
```

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。