cli: name --target and echo the rejected value when it is invalid - #34315
cli: name --target and echo the rejected value when it is invalid#34315robobun wants to merge 1 commit into
Conversation
invalid_target() discarded its value argument and reported through the generic Diagnostic path with no arg name set, producing "error: Invalid Argument ''". The message now names --target, quotes the rejected value, and lists the valid choices, matching the --format error. Also stop Debug-formatting bun_ast::Target in the --bytecode / --app / --server-components conflict errors (which printed "Browser" instead of "browser"); echo back the user's --target value instead.
|
Warning Review limit reached
Next review available in: 13 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (3)
Comment |
|
Updated 2:24 AM PT - Jul 16th, 2026
❌ @robobun, your commit 75b63a9 has 3 failures in
🧪 To try this PR locally: bunx bun-pr 34315That installs a local version of the PR into your bun-34315 --bun |
|
Status: ready for review.
CI build #73717 has three unrelated red tests, all of which are also failing on other branches and already being tracked separately:
None of these touch CLI argument parsing; this diff only changes error-message text on |
There was a problem hiding this comment.
LGTM — small, self-contained CLI error-message fix.
Checked that invalid_target and parse_build_command_options have only the one call site each, so the dropped diag param is fully accounted for. The --server-components case re-reads args.option(b"--target") because the raw byte slice is out of scope there (only the enum is bound); unwrap_or_default is defensive but the non-server-side branch is only reachable when --target was passed. New tests mirror the existing --format test in the same describe block.
Extended reasoning...
Overview
This PR fixes two cosmetic CLI error-message regressions in bun build:
invalid_target()insrc/runtime/cli/mod.rswas discarding the rejected value and reporting an emptyInvalid Argument ''. It now printsInvalid value for --target: "<value>". Must be 'browser', 'node', 'macro', or 'bun'.viaOutput::err_generic+bun::fmt::quote, matching the existing--formaterror path. The now-unuseddiagparameter is dropped from the signature and fromparse_build_command_options.- Three conflict errors in
Arguments.rs(--bytecode,--app,--server-componentsvs non-bun target) were formatting the enum with{:?}(Browser) instead of echoing the user's spelling (browser). They now printBStr::new(target)(or re-readargs.option(b"--target")for the server-components block where the raw slice is out of scope).
Tests are added to the existing CLI argument error messages block in test/bundler/cli.test.ts.
Security risks
None. This changes only error-message text on already-failing CLI paths that immediately Global::exit(1) / Global::crash(). No parsing, validation, or control-flow semantics change.
Level of scrutiny
Low. The diff is ~30 lines of Rust touching cold error paths and ~40 lines of test. I verified via grep that invalid_target has exactly one call site (Arguments.rs:1996) and parse_build_command_options has exactly one call site (Arguments.rs:1348), both updated. The --server-components block re-reads args.option(b"--target") rather than using a local because at that point only the api::Target enum is bound (if let Some(target) = opts.target), not the raw byte slice; .unwrap_or_default() yields an empty string if --target wasn't passed, but the non-server-side branch is only reachable via browser/node which require the flag, so this is defensive rather than load-bearing.
Other factors
- The new error message follows the exact pattern of the existing
--formaterror (bun::fmt::quote+ list of accepted values), which is already tested in the same describe block. - The new tests use
tempDir,await using, drain stdout/stderr/exited concurrently, and assert content before exit code — matching harness conventions and the sibling--formattest. - The bug-hunting system found no issues.
- No prior review comments to address; only bot noise on the timeline.
What
bun build --target=<invalid>lost both the flag name and the rejected value in its error message, and the--bytecode/--app/--server-componentsconflict errors leaked RustDebugformatting (Received: Browserinstead ofReceived: browser).Repro
Cause
invalid_target()insrc/runtime/cli/mod.rstook the rejected value as_targetbut never read it, reporting throughDiagnostic::reportwithError::InvalidArgument. Because--targetitself parsed fine (only its value was rejected), theDiagnosticcarried no arg name, so the renderer emitted an empty''. This regressed in #33909 which collapsed the formerInvalidTargetvariant into the genericInvalidArgumentpath.Separately, three conflict errors in
Arguments.rsformattedbun_ast::Targetwith{:?}(Browser,Node, ...) instead of the user-facing spelling.Fix
invalid_target()now printsInvalid value for --target: "<value>". Must be 'browser', 'node', 'macro', or 'bun'.viaOutput::err_generic+bun::fmt::quote, matching the existing--formaterror. The now-unuseddiagparameter is dropped (and with it fromparse_build_command_options).--bytecode,--app, and--server-componentserrors echo the user's--targetvalue verbatim instead of theDebugrepr of the enum.After
Tests
Added to the existing
CLI argument error messagesblock intest/bundler/cli.test.ts:test.eachovernodejs/web/deno/ empty string for the invalid-target message--bytecode --target=browserfor the lowercase spellingno test proof · iteration 0 · Platform-specific test(s) that do not run on this machine. Deferring to CI, which covers all platforms: test/bundler/cli.test.ts