Skip to content

fix(shell): builtin rm returns wrong exit code in quiet mode#27280

Merged
Jarred-Sumner merged 1 commit intomainfrom
claude/fix-shell-rm-quiet-exitcode
Mar 1, 2026
Merged

fix(shell): builtin rm returns wrong exit code in quiet mode#27280
Jarred-Sumner merged 1 commit intomainfrom
claude/fix-shell-rm-quiet-exitcode

Conversation

@robobun
Copy link
Collaborator

@robobun robobun commented Feb 20, 2026

Summary

  • Fixed builtin rm returning exit code 0 instead of 1 when a file doesn't exist and .quiet() or .text() is used
  • The next() function had a hardcoded done(0) that ignored the stored exit code, only affecting the quiet/pipe code path
  • Also fixed onShellRmTaskDone to use POSIX-conventional exit code 1 instead of raw errno values

Closes #18161

Test plan

  • New regression test test/regression/issue/18161.test.ts covering:
    • .quiet() throws on rm failure
    • .nothrow().quiet() returns non-zero exit code
    • .text() throws on rm failure
    • .quiet() returns 0 on successful rm
    • Exit code matches between quiet and non-quiet modes
  • Verified test fails with USE_SYSTEM_BUN=1 (2 of 5 tests fail)
  • Verified test passes with bun bd test
  • Existing throw.test.ts tests pass
  • Existing bunshell.test.ts tests have no new failures (4 pre-existing quiet subprocess timeout failures)

🤖 Generated with Claude Code

The `rm` builtin's `next()` function had a hardcoded `return this.bltn().done(0)`
for the `.done` state, ignoring the exit code stored in `this.state.done.exit_code`.
This caused `.quiet()` and `.text()` to always report exit code 0 for `rm` failures,
since the quiet code path goes through `next()` rather than `onIOWriterChunk()`.

Also fixed `onShellRmTaskDone` to use exit code 1 (matching POSIX convention) instead
of the raw errno value.

Closes #18161

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

robobun commented Feb 20, 2026

Updated 9:57 AM PT - Feb 20th, 2026

❌ Your commit 623234fa has 6 failures in Build #37732 (All Failures):


🧪   To try this PR locally:

bunx bun-pr 27280

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

bun-27280 --bun

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 20, 2026

No actionable comments were generated in the recent review. 🎉


Walkthrough

This PR fixes exit code handling in the shell rm builtin to preserve actual exit codes instead of always returning 0, and adds regression tests validating the fix for the .quiet() flag behavior.

Changes

Cohort / File(s) Summary
Exit Code Handling
src/shell/builtin/rm.zig
Updated the builtin completion logic to return the actual exit code stored in this.state.done.exit_code instead of always returning 0. Changed error handling to set exit code to 1 when errors are present, otherwise 0.
Regression Tests
test/regression/issue/18161.test.ts
New test file validating .quiet() flag behavior with the rm command, covering failure scenarios with nonexistent files, success paths with existing files, and consistency checks between quiet and non-quiet variants.
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main fix: builtin rm returning wrong exit code in quiet mode, which matches the primary code changes.
Description check ✅ Passed The description covers what the PR does, the root cause, and includes comprehensive test plans with verification steps.
Linked Issues check ✅ Passed The PR directly addresses issue #18161 by fixing exit code handling in quiet mode and ensuring proper error throwing behavior.
Out of Scope Changes check ✅ Passed All changes in rm.zig and the new test file are directly related to fixing the quiet mode exit code issue described in #18161.

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

@claude
Copy link
Contributor

claude bot commented Feb 20, 2026

62323 — Looks good!

Reviewed 2 files across src/shell/builtin/ and test/regression/issue/: Fixes exit code handling in the shell rm builtin when quiet mode (.quiet() or .text()) is enabled, by propagating the stored exit code instead of hardcoding 0 and normalizing error exit codes to POSIX-conventional 1.

@Jarred-Sumner Jarred-Sumner merged commit 61f3bcb into main Mar 1, 2026
49 of 64 checks passed
@Jarred-Sumner Jarred-Sumner deleted the claude/fix-shell-rm-quiet-exitcode branch March 1, 2026 08:40
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.

Calling shell.quiet() sets exit code to 0 and never throws

2 participants