bun icon indicating copy to clipboard operation
bun copied to clipboard

Prettier experimental-cli parallel mode returns undefined rejection reason

Open nicksrandall opened this issue 1 month ago • 1 comments

What version of Bun is running?

1.3.3

What platform is your computer?

Darwin arm64 (macOS 26.2)

What steps can reproduce the bug?

  1. Create a directory with some TypeScript/JavaScript files
  2. Run prettier's experimental CLI with the --bun flag in parallel mode (default):
bunx --bun prettier --experimental-cli --check .

What is the expected behavior?

Prettier should check all files and report formatting status.

What do you see instead?

A TypeError crash in prettier's experimental CLI:

12466 |     } else {
12467 |       const error = fileResult.reason;
12468 |       if (error.name === "UndefinedParserError") {
                  ^
TypeError: undefined is not an object (evaluating 'error.name')
      at runGlobs (/path/to/node_modules/.bun/[email protected]/node_modules/prettier/internal/experimental-cli.mjs:12468:11)

The issue is that fileResult.reason is undefined when it should be an Error object.

Workarounds that confirm this is Bun-specific

All of these work correctly:

Command Result
bunx --bun prettier --experimental-cli --check . ❌ Crashes
bunx prettier --experimental-cli --check . (Node runtime) ✅ Works
bunx --bun prettier --experimental-cli --check . --no-parallel ✅ Works
bunx --bun prettier --check . (regular CLI) ✅ Works

Analysis

The experimental CLI uses Promise.allSettled() for parallel file processing. When a promise is rejected, the reason property should contain the error. Under Bun's runtime, some rejected promises have reason: undefined instead of the actual error object.

This suggests a bug in how Bun handles Promise.allSettled() with rejected promises in worker threads or parallel execution contexts.

Additional information

  • Prettier version: 3.7.3
  • Node version (for comparison): v22.19.0
  • The bug is reproducible consistently

nicksrandall avatar Dec 02 '25 00:12 nicksrandall

Found 1 possible duplicate issue:

  1. https://github.com/oven-sh/bun/issues/21901

This issue will be automatically closed as a duplicate in 3 days.

  • If your issue is a duplicate, please close it and 👍 the existing issue instead
  • To prevent auto-closure, add a comment or 👎 this comment

🤖 Generated with Claude Code

github-actions[bot] avatar Dec 02 '25 00:12 github-actions[bot]