Skip to content

Promise.any: give the rejected AggregateError a stack, message, and no spurious cause - #35532

Closed
robobun wants to merge 2 commits into
mainfrom
farm/07410bab/promise-any-aggregate-error
Closed

robobun wants to merge 2 commits into
mainfrom
farm/07410bab/promise-any-aggregate-error

Conversation

@robobun

@robobun robobun commented Jul 25, 2026 •

Copy link
Copy Markdown
Collaborator

What does this PR do?

Bumps WEBKIT_VERSION to pick up oven-sh/WebKit#340 and adds test coverage for the AggregateError that Promise.any rejects with.

Problem

The AggregateError rejected by Promise.any has no .stack (it is undefined, not even an own property), an empty .message, and a spurious own cause: undefined:

try { await Promise.any([Promise.reject(new Error("r1")), Promise.reject("r2")]); }
catch (e) {
  console.log("stack:", typeof e.stack, "msg:", JSON.stringify(e.message),
              "own:", Object.getOwnPropertyNames(e));
  console.log("hasOwnCause:", Object.prototype.hasOwnProperty.call(e, "cause"));
}
// node: stack: string  msg: "All promises were rejected"  own: [stack,message,errors]  hasOwnCause: false
// bun:  stack: undefined  msg: ""  own: [cause,errors]  hasOwnCause: true

A user-constructed new AggregateError(...) in the same process has a stack and no own cause, so this is specific to the Promise.any construction path. The result is that the most common real-world AggregateError (a Promise.any fan-in where every branch rejected) is an undebuggable rejection.

Cause

The five Promise.any rejection sites in JSPromiseConstructor.cpp / JSMicrotask.cpp call createAggregateError(vm, structure, errors, String(), jsUndefined()). ErrorInstance::finishCreation installs cause whenever the passed JSValue is non-empty, so jsUndefined() becomes an own cause: undefined; the null String() leaves no own message.

The async paths (promiseAnyResolveJob, the reject element functions) run from a native internal microtask with no JS frames on the stack, so m_stackTrace is an empty vector and materializeErrorInfoIfNeeded's Bun branch (gated on !m_stackTrace->isEmpty()) never runs, leaving .stack unmaterialized.

Fix (in oven-sh/WebKit#340)

  • Add createAggregateErrorForPromiseAnyRejection, which passes an empty JSValue() for cause and, under USE(BUN_JSC_ADDITIONS), V8's "All promises were rejected" message. Route all five call sites through it.
  • In materializeErrorInfoIfNeeded, drop the isEmpty() gate on the Bun branch so the embedder hook still runs for zero-frame errors and produces the "Name: message" header; line/column/sourceURL are only set when there are frames.

Verification

With this bump:

stack: string msg: "All promises were rejected" own: [ "message", "errors", "stack" ]
hasOwnCause: false

which matches Node. The new test covers every Promise.any rejection path: the fast-path internal microtask, the empty-iterable synchronous rejection, the subclass slow path (both async and empty), and a custom thenable. It also asserts that user-constructed AggregateError with and without an explicit cause is unchanged.

This is the error-object half of #29157; #35174 covers the console.dir / Bun.inspect print path that currently skips the aggregate header. With both in, the #29157 repro prints AggregateError: All promises were rejected followed by the member errors.

Also in this range (oven-sh/WebKit 549170099226..6e83cef951dc)

  • #328 inspector: release throw scope before tail-calling impl in injected-script prototype host functions
  • #317 LiteralParser: throw RangeError on OOM when copying a JSON string value
  • #331 SignalsWin: fix VEH return value and register behind AddressSanitizer's handler
  • #332 Heap: make minEdenToOldGenerationRatio a JSC option

Draft: WEBKIT_VERSION currently points at the preview build of oven-sh/WebKit#340. Once that PR is merged this will be retargeted at the resulting autobuild-<sha> on main.

…s cause

Bumps WEBKIT_VERSION to pick up oven-sh/WebKit#340 and adds coverage for
the AggregateError rejected by Promise.any on every code path (fast path
microtask, empty iterable, subclass slow path, thenable).
@robobun

robobun commented Jul 25, 2026 •

Copy link
Copy Markdown
Collaborator Author

The preview build of oven-sh/WebKit#340 is published as autobuild-preview-pr-340-6e83cef9.

Verified locally with bun bd against that prebuilt:

$ bun bd test test/js/node/promise/promise-any-aggregate-error.test.ts
 7 pass  0 fail

and USE_SYSTEM_BUN=1 shows 6 of 7 failing, so the test exercises the fix.

CI #80570 finished with no code failures: the three build-cpp lanes that were assigned an agent (darwin-x64, linux-x64-asan, freebsd-x64) all passed; the remaining ten expired in the os=linux queue without ever being picked up, so no test jobs ran. ci:errors classifies the resulting "step failed outside runner" entries as pre-existing.

Ready for review. Once oven-sh/WebKit#340 is merged I'll retarget WEBKIT_VERSION from the preview tag to the merged sha and re-run CI.

@github-actions

Copy link
Copy Markdown
Contributor

Found 1 issue this PR may fix:

  1. Bun throws Error instead of AggregateError on Promise.reject within Promise.any #29157 - Reports that Promise.any produces an error with an empty message instead of "All promises were rejected" and displays as a plain Error rather than AggregateError, which this PR directly fixes

If this is helpful, copy the block below into the PR description to auto-close this issue on merge.

Fixes #29157

🤖 Generated with Claude Code

@robobun

robobun commented Jul 25, 2026 •

Copy link
Copy Markdown
Collaborator Author
Updated 3:29 AM PT - Jul 25th, 2026

@robobun, your commit 476fe3c is building: #80570

Jarred-Sumner pushed a commit that referenced this pull request Jul 25, 2026
…35534)

Adds a self-contained GitHub Action that scans `claude`-labeled PRs for
multi-line comment blocks added under `src/` and leaves a review line
comment on each one asking for it to be deleted (and the thread resolved
once done).

### Behavior

- Triggers on `pull_request_target` (`opened` / `synchronize` /
`reopened` / `labeled`), gated on `github.repository == 'oven-sh/bun'`
and the `claude` label being present. The `labeled` trigger covers the
normal case where `auto-label-claude-prs.yml` applies the label after
open.
- Fetches PR files via `pulls.listFiles` and parses the unified diff in
`actions/github-script`. No repo checkout.
- A group is **2+ consecutive added lines** that are pure comment lines
(`//`, `///`, `//!`, `/* ... */`, `* ` continuation) in `.rs` / `.c` /
`.cpp` / `.h` / `.ts` / `.js` and friends. Groups containing `SAFETY:`
are skipped.
- Posts one standalone review line comment per consecutive group via
`pulls.createReviewComment` (no review summary).
- Each comment carries `<!-- comment-cop:<path>:<sha12> -->` keyed on
the group's content hash, so reruns (new pushes, relabels) skip groups
that already have a marker.
- On each run, any existing comment-cop thread whose flagged block is no
longer present in the diff is auto-resolved via `resolveReviewThread`.

### Verification

Dry-ran the parser against the five most recent open `claude` PRs via
`gh api repos/oven-sh/bun/pulls/<n>/files`:

```
#35531  src/runtime/webcore/Blob.rs:5245-5246
#35529  src/http_jsc/websocket_client.rs:907-910
#35528  src/runtime/webcore/FileSink.rs:917-920
#35526  src/http_jsc/websocket_client.rs:2179-2182
#35532  (clean)
```

Cross-checked `#35531` line numbers against the fetched head ref;
`Blob.rs:5245` is the first line of the flagged block. `actionlint` and
prettier both pass.

<!-- robobun:evidence:begin -->

---

**no test proof** · iteration 0 · build/CI scripts only; test-proof not
applicable

<!-- robobun:evidence:end -->
Jarred-Sumner pushed a commit that referenced this pull request Jul 27, 2026
…35534)

Adds a self-contained GitHub Action that scans `claude`-labeled PRs for
multi-line comment blocks added under `src/` and leaves a review line
comment on each one asking for it to be deleted (and the thread resolved
once done).

### Behavior

- Triggers on `pull_request_target` (`opened` / `synchronize` /
`reopened` / `labeled`), gated on `github.repository == 'oven-sh/bun'`
and the `claude` label being present. The `labeled` trigger covers the
normal case where `auto-label-claude-prs.yml` applies the label after
open.
- Fetches PR files via `pulls.listFiles` and parses the unified diff in
`actions/github-script`. No repo checkout.
- A group is **2+ consecutive added lines** that are pure comment lines
(`//`, `///`, `//!`, `/* ... */`, `* ` continuation) in `.rs` / `.c` /
`.cpp` / `.h` / `.ts` / `.js` and friends. Groups containing `SAFETY:`
are skipped.
- Posts one standalone review line comment per consecutive group via
`pulls.createReviewComment` (no review summary).
- Each comment carries `<!-- comment-cop:<path>:<sha12> -->` keyed on
the group's content hash, so reruns (new pushes, relabels) skip groups
that already have a marker.
- On each run, any existing comment-cop thread whose flagged block is no
longer present in the diff is auto-resolved via `resolveReviewThread`.

### Verification

Dry-ran the parser against the five most recent open `claude` PRs via
`gh api repos/oven-sh/bun/pulls/<n>/files`:

```
#35531  src/runtime/webcore/Blob.rs:5245-5246
#35529  src/http_jsc/websocket_client.rs:907-910
#35528  src/runtime/webcore/FileSink.rs:917-920
#35526  src/http_jsc/websocket_client.rs:2179-2182
#35532  (clean)
```

Cross-checked `#35531` line numbers against the fetched head ref;
`Blob.rs:5245` is the first line of the flagged block. `actionlint` and
prettier both pass.

<!-- robobun:evidence:begin -->

---

**no test proof** · iteration 0 · build/CI scripts only; test-proof not
applicable

<!-- robobun:evidence:end -->
@github-actions

Copy link
Copy Markdown
Contributor

Closing this PR because it has been inactive for more than 90 days.

@github-actions github-actions Bot closed this Oct 24, 2026
@robobun

robobun commented Oct 24, 2026

Copy link
Copy Markdown
Collaborator Author

The stale sweep closed this. The work continues in oven-sh/WebKit#895, with a smaller scope.

The test rows for Bun are in the body of oven-sh/WebKit#895. They go in with the WebKit bump that first includes that change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants