Repository navigation
fix: report command substitution status from assignment-only commands - #232
ferdingler merged 6 commits into
Conversation
8696777 to
bb7bd6f
Compare
|
@strandly-the-agent Please review this PR |
strandly-the-agent
left a comment
There was a problem hiding this comment.
Approve. The fix is correct and matches bash on every substitution path we tried, with no regressions from the change itself. One heads-up: it makes an existing set -e bug easier to hit. I filed that as #259; it shouldn't block this PR.
The heads-up: errexit isn't suppressed inside function, group, eval or source bodies run from a tested context (f || handler). Assignments used to always return 0, which hid this. With the fix, scripts like these behave differently from main:
set -e; f() { x=$(false); echo in-f; }; f || echo caught # bash/main: in-f | PR: caught
set -e; { x=$(false); echo in-g; } || echo caught # bash/main: in-g | PR: no output, rc=1
You get the same divergence on main with a plain false, so the root cause is older than this PR. Worth a note in the PR description, or landing #259 soon after.
What I verified
- Head
bb7bd6f:cargo test --workspace --all-targets --no-fail-fastgave 2394 passed, 0 failed, including 1810 inshell_integrationand the differential suite. - An adversarial pass ran 334 scripts through bash,
mainand this PR.- 124 went from wrong to matching bash.
- None that matched bash on
mainstopped matching because of this change. The only new mismatches are the errexit interaction above andwait, which already returns the last job's status onmain.
- Both
capture_outputcallers report the status:expand_part($(), backticks,${v:-$(…)}) andexpand_arith_expr($(( ))). - Other assignment forms also match bash:
x+=,a[0]=,eval 'x=$(exit 3)',{ x=$(exit 3); }, and an EXIT trap reading$?. Bonus:while x=$(exit 3); dono longer loops forever. - No stale status can leak between commands. The field is only read at
src/exec.rs:3213, always after the reset at:3160in the samerun_pipelinecall, andfork()starts it atNone.
Non-blocking (4)
x=$(fi)returns 1 with no error message, becausecapture_outputdrops the parse error (src/exec.rs:1681). Bash rejects the whole script with rc 2. Theassign_subst_parse_error_statustest pins the 1, which matches how this shell already handles top-level syntax errors. That's fine, just be aware the test locks it in.echo | x=$(false); echo $?: bash prints 1, this PR prints 0. An assignment-only command as the last stage of a pipeline doesn't take the new path. The PR doesn't claim to cover this.$?isn't updated during expansion: in bash,x=$(exit 3) y=$?sets y=3 andecho $(exit 3) $?prints 3. Here both give 0, before and after this PR. Is that worth tracking under #207?- Also unchanged by this PR:
$(exit 300)returns 300 because statuses are never cut to 8 bits, and stderr from inside$( )is dropped in-cmode, soset -e; x=$(nonexistent)exits 127 without printing an error.
bb7bd6f to
dd7df1a
Compare
|
@strandly-the-agent Please review this PR Added the arithmetic-substitution regression and proved it catches missing status propagation at that caller. I also rebased over the newly merged #222, preserving its exit/refusal state alongside substitution status, and added the #259 strict-mode follow-up to the description. No new production behavior beyond that conflict resolution. The full Rust checks and 48 Bash comparisons pass, including arithmetic, function exits, and pipefail together. Please re-review dd7df1a. |
strandly-the-agent
left a comment
There was a problem hiding this comment.
Still approve. The earlier finding is fixed, and there's one small cleanup.
- ✅ Arithmetic coverage (fixed):
assign_arith_subst_statusis in. I disabled status propagation at the$(( ))caller (src/exec.rs:780) and the test fails. Restored, it passes. - ✅ Rebase over #222: the source diff is unchanged apart from placing the new field next to
pending_exit/refused_arrayinsrc/os.rs. I don't see any interaction, since substitutions run in a forkedProcessand that fork resets all three fields. - 🟡 New
dead_codewarning:run_capturinghas no callers left, so everycargo buildwarns about it (inline). I missed this on the first pass, sorry.
What I verified
dd7df1amerged with currentmain(merges cleanly, sincemainis now 3 commits ahead):cargo test --workspace --all-targets --no-fail-fastgives 2473 passed, 0 failed.cargo fmt --checkpasses.cargo clippy: 15 warnings, against 14 onmain. The extra one is therun_capturingwarning.- #259 is now noted in the description.
|
@strandly-the-agent Please review this PR Removed the unused capture wrapper and its obsolete documentation link in db996fc. The full Rust checks and 48 Bash comparisons pass, and clippy no longer reports that dead-code warning. Both the current-main and pending #235 merge trees are clean and contain no remaining caller. Please re-review this cleanup. |
strandly-the-agent
left a comment
There was a problem hiding this comment.
Approve. db996fc fixes the dead-code finding, and nothing is left open from my reviews.
- ✅
run_capturingis gone, and therun_capturing_statusdoc no longer links to it. - ✅ No callers are left, including in
main's newer captured-output fixes (#231, #233).db996fcmerges cleanly with currentmain.
What I verified
All on db996fc merged with origin/main @ d21a4e3:
cargo test --workspace --all-targets --no-fail-fast: 2482 passed, 0 failedcargo fmt --check: cleancargo clippy --workspace --all-targets: 14 warnings, the same asmain, with no dead-code warning
Description
Assignment-only commands always reported success, even when a command substitution failed. That meant an error handler after an assignment could be skipped despite the command failing.
I made assignment-only commands and lone substitutions return the last substitution's status, including substitutions inside arithmetic expressions. This exposes an existing strict-mode issue in functions and groups used as conditions, tracked separately in #259; redirects on assignment-only commands also remain outside this fix.
The full Rust checks and 48 Bash comparisons pass, including the merged function-exit and pipefail behavior. I added arithmetic coverage and deliberately disabled its status propagation to confirm the test fails, then restored it and confirmed it passes.
Related Issues
Part of #207
Documentation PR
N/A
Type of Change
Bug fix
Testing
How have you tested the change? Verify that the changes do not break functionality or introduce new warnings.
cargo test --workspace --all-targets,pytest tests/python,npm test)cargo fmtandcargo clippyChecklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.