Skip to content

fix(shell): report correct illegal option character in mv command#26750

Open
robobun wants to merge 3 commits intomainfrom
claude/fix-mv-illegal-option-error-message
Open

fix(shell): report correct illegal option character in mv command#26750
robobun wants to merge 3 commits intomainfrom
claude/fix-mv-illegal-option-error-message

Conversation

@robobun
Copy link
Collaborator

@robobun robobun commented Feb 5, 2026

Summary

  • Fixed mv command reporting incorrect character in illegal option error messages
  • The error was showing "-" for all unrecognized flags instead of the actual flag character

Before: mv -T ./a ./b shows mv: illegal option -- -
After: mv -T ./a ./b shows mv: illegal option -- T

Test plan

  • Added regression test in test/regression/issue/26749.test.ts
  • Tests verify correct error character for -T, -X, -fX, and -vZ flags
  • Verified test fails with system Bun and passes with debug build

Fixes #26749

🤖 Generated with Claude Code

The mv command was reporting "-" for all unrecognized flags instead of
the actual flag character. For example, `mv -T` would show
"mv: illegal option -- -" instead of "mv: illegal option -- T".

The bug was in parseFlag() where the else branch returned a hardcoded
"-" instead of the actual unrecognized character from the flag string.

Fixes #26749

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@github-actions github-actions bot added the claude label Feb 5, 2026
@robobun
Copy link
Collaborator Author

robobun commented Feb 5, 2026

Updated 12:17 AM PT - Feb 5th, 2026

❌ Your commit 78c1023b has 2 failures in Build #36582 (All Failures):


🧪   To try this PR locally:

bunx bun-pr 26750

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

bun-26750 --bun

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 5, 2026

Walkthrough

Flag parsing in the mv builtin was changed to track the index of each short flag and return the specific invalid option character on error; regression tests were added to verify the precise "mv: illegal option -- " messages for several invalid-flag scenarios.

Changes

Cohort / File(s) Summary
Error Reporting Fix
src/shell/builtin/mv.zig
Flag parsing now iterates with an index to identify the offending short flag and returns the specific invalid option character (computed from the flag substring) instead of a generic "-" when reporting illegal options.
Regression Tests
test/regression/issue/26749.test.ts
Adds four tests asserting mv emits mv: illegal option -- <CHAR> and a non-zero exit code for invalid-flag cases (examples: -T, -X, -fX, -vZ).
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and specifically describes the main fix: reporting the correct illegal option character in mv command error messages.
Description check ✅ Passed The PR description covers the key aspects with clear before/after examples, test plan details, and issue reference, though it doesn't strictly follow the template structure provided.
Linked Issues check ✅ Passed The PR successfully addresses issue #26749 by fixing the mv command to report the actual illegal option character instead of a generic dash, with comprehensive regression tests.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing the reported issue: the mv.zig fix and regression tests address the illegal option reporting problem without unrelated modifications.

✏️ 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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@test/regression/issue/26749.test.ts`:
- Around line 12-15: Add an explicit assertion for the process exit code in the
catch block: after decoding stderr and the existing
expect(stderr).toContain(...) add an assertion on the captured ShellError (const
err = e as Bun.$.ShellError) such as expect(err.code).toBe(<expectedExitCode>)
or at minimum expect(typeof err.code).toBe("number") &&
expect(err.code).not.toBe(0); apply the same pattern to the other related test
cases to make exit-code verification explicit.

@claude
Copy link
Contributor

claude bot commented Feb 5, 2026

Code Review

No issues found. Checked for bugs and CLAUDE.md compliance.

Address code review feedback to verify exit codes in catch blocks.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@robobun
Copy link
Collaborator Author

robobun commented Feb 5, 2026

Addressed the review feedback - added expect(err.exitCode).not.toBe(0) to all four test cases in commit 8bda817.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@test/regression/issue/26749.test.ts`:
- Around line 7-65: Replace the four nearly identical tests with a single
parameterized test using test.each: create an array of cases like [["-T","T"],
["-X","X"], ["-fX","X"], ["-vZ","Z"]] and write test.each(cases)("mv reports
correct illegal option for %s", async (flag, expectedChar) => { $.throws(true);
try { await Bun.$`mv ${flag} ./a ./b`; expect.unreachable("should have thrown");
} catch (e: unknown) { const err = e as Bun.$.ShellError; const stderr = new
TextDecoder().decode(err.stderr); expect(stderr).toContain(`mv: illegal option
-- ${expectedChar}`); expect(err.exitCode).not.toBe(0); } finally { $.nothrow();
} }); ensure you reference the existing Bun.$ invocation and the
$.throws/$.nothrow usage so behavior stays identical.

Address code review feedback to reduce duplication by using parameterized tests.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@robobun
Copy link
Collaborator Author

robobun commented Feb 5, 2026

Refactored the tests to use test.each as suggested, reducing duplication from 65 lines to 27 lines (commit 78c1023).

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.

Bun shell mv -T ./a ./b fails with "mv: illegal option -- -"

1 participant