Skip to content

cli: make several unhelpful error messages actionable#32470

Open
robobun wants to merge 3 commits into
mainfrom
farm/70b6011a/improve-cli-error-messages
Open

cli: make several unhelpful error messages actionable#32470
robobun wants to merge 3 commits into
mainfrom
farm/70b6011a/improve-cli-error-messages

Conversation

@robobun

@robobun robobun commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

What

A handful of CLI error messages that gave the user nothing to act on now echo the offending value and/or show what a correct invocation looks like. Same spirit as #32465.

Before / After

bun install --linker=isoalted (typo)

- error: Expected --linker to be one of 'isolated' or 'hoisted'
+ error: Invalid value for --linker: "isoalted". Must be 'isolated' or 'hoisted'.

bun patch (no argument)

- error: Missing pkg to patch
+ error: Missing package name to patch.
+   Usage: bun patch <package>[@<version>]
+ note: Run 'bun patch --help' for more information

bun patch --commit / bun patch-commit (no argument)

- error: Missing pkg to patch
+ error: Missing path to the package directory containing your changes.
+   Usage: bun patch --commit node_modules/<package>
+ note: Run 'bun patch --help' for more information

bun build --format=commonjs

- error: Invalid format - must be esm, cjs, or iife
+ error: Invalid value for --format: "commonjs". Must be 'esm', 'cjs', or 'iife'.

bun build --loader text (missing :)

- error: expected ":" separator
+ error: --loader "text" is missing a ":" separator. Expected --loader .ext:loader, for example --loader .md:text

bun build --define FOO (missing =)

- error: expected ":" separator
+ error: --define "FOO" is missing a ":" or "=" separator. Expected --define key=value, for example --define process.env.NODE_ENV='"production"'

bun run --filter='*' script with a workspace package whose package.json is unreadable/malformed

- warn: Failed to read package.json
+ warn: Failed to read "/path/to/packages/broken/package.json", skipping this workspace package

Why these matter

  • --linker / --format: every sibling flag in the same file already echoes the bad value; these two were the odd ones out. A user who typos isoalted or writes commonjs instead of cjs currently gets no pointer at what they typed.
  • --loader / --define: the old message didn't even say which flag tripped. Both flags go through the same helper, so bun build --loader foo --define BAR gave an identical message for either mistake.
  • bun patch: "pkg" is jargon and there was no hint at what to pass.
  • --filter: in a monorepo with many packages, "Failed to read package.json" doesn't tell you which one.

Verification

New tests in each of the relevant existing files:

bun bd test test/bundler/cli.test.ts -t "CLI argument error messages"                        # 3 pass
bun bd test test/cli/install/bun-patch.test.ts -t "error messages"                           # 3 pass
bun bd test test/cli/install/isolated-install.test.ts -t "invalid --linker"                  # 1 pass
bun bd test test/cli/run/filter-workspace.test.ts -t "warning names which package.json"      # 1 pass

All 8 fail under USE_SYSTEM_BUN=1 (they assert on content the old messages never had).

One existing assertion in filter-workspace.test.ts that matched the old generic warning text has been tightened to also assert the path is present.

- 'bun install --linker=<bad>' now echoes the rejected value
- 'bun patch' / 'bun patch --commit' / 'bun patch-commit' with no
  positional now show a one-line usage example and point at --help
- 'bun build --format=<bad>' now echoes the rejected value
- 'bun build --loader <bad>' and '--define <bad>' (no ':' / '=') now
  name which flag rejected the token, echo the token, and show an
  example of the expected shape
- 'bun run --filter' now names which workspace package.json it
  failed to read instead of a bare 'Failed to read package.json'
@robobun

robobun commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator Author
Updated 4:35 PM PT - Jun 17th, 2026

@robobun, your commit 77625c7 has 3 failures in Build #63227 (All Failures):


🧪   To try this PR locally:

bunx bun-pr 32470

That installs a local version of the PR into your bun-32470 executable, so you can run:

bun-32470 --bun

@coderabbitai

coderabbitai Bot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 231953af-9c8f-4fde-9d5f-df8683401b45

📥 Commits

Reviewing files that changed from the base of the PR and between c3293c1 and 77625c7.

📒 Files selected for processing (1)
  • test/cli/run/filter-workspace.test.ts

Walkthrough

Improves CLI error messages across bun install, bun build, bun patch, and bun run --filter to echo the invalid value and list accepted options or provide usage guidance. Regression tests are added for each changed message path.

Changes

CLI Error Message Improvements

Layer / File(s) Summary
Install: --linker and bun patch/patch-commit error messages
src/install/PackageManager/CommandLineArguments.rs, test/cli/install/isolated-install.test.ts, test/cli/install/bun-patch.test.ts
--linker invalid-value error now echoes the provided value and lists 'isolated' or 'hoisted'. Missing-positional errors for bun patch and bun patch-commit now emit context-specific messages (distinguishing commit mode) and append a --help note. Three regression tests added.
Build: --format and colon-list (--loader/--define) error messages
src/runtime/cli/Arguments.rs, src/runtime/cli/colon_list_type.rs, test/bundler/cli.test.ts
--format invalid-value error quotes the provided string and lists 'esm', 'cjs', 'iife'. ColonListType::load emits a type-specific message and exits on missing separator, removing the InvalidSeparator return arm from ColonListType::resolve. Three bun build regression tests added.
Filter workspace: package.json parse failure warning
src/runtime/cli/filter_run.rs, test/cli/run/filter-workspace.test.ts
Warning on package.json parse failure now includes the quoted file path and states the package is being skipped. Existing test assertion tightened and a new regression test added.

Suggested reviewers

  • RiskyMH
  • dylan-conway
  • alii
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main objective of the PR: improving CLI error messages to be more actionable and helpful.
Description check ✅ Passed The PR description comprehensively covers both required sections with clear structure, concrete before/after examples, and verification information.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@test/cli/run/filter-workspace.test.ts`:
- Around line 607-618: The test is not validating the command success or the
actual execution of the valid workspace package. Modify the test to capture the
exit code from the Bun.spawn call (currently proc.exited is awaited but ignored)
and add assertions that verify both stdout output and exit code. First check
that stdout contains expected output from the valid workspace package execution,
then assert that the exit code is 0 to confirm the command succeeded. This
ensures the test validates that the valid package actually ran successfully, not
just that error warnings were logged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 2bb01511-9184-4955-bad0-d89c3313aebf

📥 Commits

Reviewing files that changed from the base of the PR and between 65f12bd and 4a5d486.

📒 Files selected for processing (8)
  • src/install/PackageManager/CommandLineArguments.rs
  • src/runtime/cli/Arguments.rs
  • src/runtime/cli/colon_list_type.rs
  • src/runtime/cli/filter_run.rs
  • test/bundler/cli.test.ts
  • test/cli/install/bun-patch.test.ts
  • test/cli/install/isolated-install.test.ts
  • test/cli/run/filter-workspace.test.ts

Comment thread test/cli/run/filter-workspace.test.ts
Comment thread test/cli/run/filter-workspace.test.ts
@robobun

robobun commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator Author

CI status: the diff itself is green. Build 63227 finished with 259 lanes passed; none of the 4 changed test files appear in any failure. The red is:

  • windows {aarch64, x64, x64-baseline} - test-bun × 25: Failed to create agent (Buildkite agent provisioning; also affecting main #63224)
  • test/integration/next-pages/test/dev-server.test.ts on darwin 26 aarch64: puppeteer chrome-headless-shell download failure ("browser folder exists but the executable is missing"; corrupted cache on the runner)
  • test/js/web/fetch/fetch-leak.test.ts on darwin 14 aarch64: RSS threshold flake in "should not leak using readable stream"

None of these touch bun install / bun build / bun patch / bun run --filter arg parsing, and none are plausibly affected by error-message string changes. All 8 new tests pass locally under bun bd test and fail under USE_SYSTEM_BUN=1. Ready for review.

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM — error-message-only changes with regression tests; my earlier nit on the filter-workspace test was addressed in 77625c7.

Extended reasoning...

Overview

This PR rewords seven CLI error/warning messages across bun install, bun build, bun patch, and bun run --filter so they echo the offending value and/or show a usage example. Source changes touch four Rust files (CommandLineArguments.rs, Arguments.rs, colon_list_type.rs, filter_run.rs); the rest is eight new regression tests plus one tightened existing assertion across four test files. Every source edit is confined to an error/warning code path that already terminated the process — no happy-path control flow changes.

The only non-string-literal change is in colon_list_type.rs, where the missing-separator case now prints and Global::exit(1) directly inside load() instead of returning Err(InvalidSeparator) for resolve() to catch and do the same thing. I verified load() has exactly one caller (resolve(), line 86) and that the two ColonListValue implementors are precisely Loader (IS_LOADER = true, → --loader message) and &'static [u8] (→ --define message), so the branch is exhaustive and the observable behavior is unchanged apart from the message text.

Security risks

None. The changes only format user-supplied CLI argument strings into error output via the existing bun_core::fmt::quote / bstr::BStr helpers (same pattern as the neighboring --registry, --cpu, --os errors in the same file). No parsing, no filesystem, no auth, no network.

Level of scrutiny

Low. These are user-facing error-string improvements on already-failing code paths, each backed by a test that asserts the new message content and a non-zero exit code. The PR description documents that all 8 tests fail under USE_SYSTEM_BUN=1, confirming they pin the new behavior. None of the touched paths are covered by CODEOWNERS.

Other factors

  • The bug-hunting system found no issues.
  • My earlier inline nit (and CodeRabbit's identical one) about asserting stdout/exitCode in the new filter-workspace test was addressed in commit 77625c7 and both threads are resolved.
  • The CI failures reported by robobun are infrastructure-only (musl build agents and "Failed to create agent" on Windows runners), not test failures related to this diff.
  • The new error strings follow the surrounding house style (Output::err_generic + fmt::quote, <d>/<cyan>/<r> markup, bun_core::note! for the help hint) used elsewhere in the same files.

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.

1 participant