anthropics / anthropics/claude-code-action

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

Đang mở
#1,747 3 bình luận 0 reaction 0 người được giao Xem trên GitHub
bug p3
Ngôn ngữ chính
TypeScript
Star
8.9k
Fork
2.1k
Chỉ số merge pull request
Chỉ số pull request đang chờ

Mô tả

#### 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;
}
```

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.