Repository navigation
fix(#553): compound's own failed redirection fires ERR again - unblock redir snapshot - #557
Merged
Merged
Conversation
…k redir snapshot PR #553's #507 pass-through gate (command_status_produced_by_body) exempted if/loop/for/case/select compounds from the post-execute ERR adjudication, and the exemption leaked one flavor it must not cover: the compound's OWN failed redirection. redir12.sub's `trap 'echo got error ERR' ERR; while ...; done </dev/null > unwritable-file` stopped printing "got error ERR", so upstream_suite_slice_snapshots went red on master (CI run 38195839266) and every PR was blocked. The wrapper's open() failure surfaces as ExecuteError::IoError; the walker's IoError arm falls through to the same gated ERR site the #507 commit added its skip at, so the trap went silent for exactly the kinds whose redirects the wrapper owns. Semantics (GNU oracle, vendored bash-5.3-16-gb4608166): GNU runs the ERR trap and the errexit jump at the compound level when the compound's own redirection fails (execute_cmd.c:849-884 - the "WHILE FOR CASE etc. with redirections" path latches was_error_trap before dispatch, sets the failure status, runs the trap, then exits under errexit; the upstream redir.right expectation pins the behavior as "got error ERR" + "after ERR trap: 1"). That path is ORTHOGONAL to the one #507 fixed: an exempt inner failure (a `&&`/`||` short-circuit arm or a `!` pipeline) reaches the compound as a body-inherited AGGREGATE with no wrapper failure, and GNU's execute_if_command family still hands that status up with no ERR/errexit look of its own. One gate keyed on node kind cannot see the difference - this restores the adjudication for the wrapper-failure flavor only. Fix: in the walker's ExecuteError::IoError arm, fire maybe_run_error_trap when the failed node is a pass-through compound kind. maybe_run_error_trap's own gates (inverted, &&/|| context, suppress, errtrace depth, recursion) keep every #507 exclusion, and the gated post-site stays skipped for these kinds, so nothing double-fires. GNU cross-check (WSL 5.3.0, stdout byte-equal after the fix): the repro prints `got error ERR` + `after ERR trap: 1`; #507's guard `set -e; if true; then false && true; fi; echo R` still prints R with rc 0; `set -e; trap 'echo E' ERR; false` still prints E and exits 1. No golden or snapshot bytes touched: redir.snap passes unchanged against the recorded baseline. Tests: cargo test --test regression upstream_suite_slice_snapshots green; full serial cargo test --no-fail-fast vs pristine master (f33c5e3), failure sets compared name-by-name bidirectionally - the only delta is upstream_suite_slice_snapshots (red on master, green here), no other test flips either way; #553's 20 new tests (issue507 x7, issue508 x5, issue509 x3, issue510 x5) and the part_025 dirs companions stay green; cargo fmt clean.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Root cause
PR #553's #507 fix gates BOTH post-execute consumers of a command's status
(the ERR trap fire and the errexit promotion) on
command_status_produced_by_body()— a node-kind test that exemptsif/while/until/for/case/selectcompounds because their nonzeroaggregate is usually inherited from an exempt inner failure (a
&&/||short-circuit arm or a!pipeline) that was already adjudicatedin the nested walk.
The gate cannot see one flavor: the compound's own failed redirection.
That failure surfaces as
ExecuteError::IoErrorfrom the redirect wrapper,the walker's IoError arm falls through to the same gated ERR site, and the
kind-based skip silenced the trap. Concretely, redir12.sub (upstream
redirection suite, vendored under
third_party/bash):stopped printing
got error ERR—upstream_suite_slice_snapshotsredirsnapshot lost exactly that one byte, master went red
(CI run 38195839266), all PRs blocked. This is also the case #553's own
commit message promised would keep adjudicating ("a compound's own failed
redirection — the wrapper's failure"); the promise held only for node kinds
outside the gate list.
GNU semantics (anchor + behavior)
GNU anchors the ERR trap and the errexit jump for a compound's own
redirection failure at the compound-command redirection setup in
execute_cmd.c (the "Handle WHILE FOR CASE etc. with redirections" path,
execute_cmd.c:849-884 in the vendored bash-5.3-16-gb4608166 mirror): the
trap state is latched before dispatch, the failure status is set, the ERR
trap runs at the compound level, then errexit exits. The upstream
redir.rightexpectation pins the stdout:got error ERR+after ERR trap: 1.That path is orthogonal to what #507 fixed: an exempt inner failure reaches
the compound as a body-inherited aggregate with no wrapper failure, and
GNU's execute_if_command family hands that status up with no ERR/errexit
look of its own. One node-kind gate cannot distinguish the two flavors, so
the fix re-enables adjudication for the wrapper-failure flavor only.
WSL GNU 5.3.0 behavioral cross-check (stdout byte-equal with this branch
after the fix):
trap 'echo got error ERR' ERR; while … done </dev/null > unwritablegot error ERR/after ERR trap: 1set -e; if true; then false && true; fi; echo R(#507 guard)R, rc 0set -e; trap 'echo E' ERR; falseE, rc 1Fix
One hunk in
src/executor/ast_exec.rs(+16): the walker'sExecuteError::IoErrorarm now firesmaybe_run_error_trapwhen the failednode is a pass-through compound kind.
maybe_run_error_trap's own gates(inverted,
&&/||context, errexit-suppression, errtrace depth,recursion guard) keep every #507 exclusion, and the gated post-site stays
skipped for these kinds, so nothing double-fires. No golden or snapshot
bytes touched —
redir.snappasses byte-identical to the recordedbaseline.
Test evidence
cargo test --test regression upstream_suite_slice_snapshots: green(was the master red); all 13 suites pass,
redir.snapunchanged.cargo test --no-fail-fast, run serially on this branch and onpristine master (f33c5e3) in identical conditions; failure sets compared
name-by-name bidirectionally: the only delta is
upstream_suite_slice_snapshots(red on master, green here) — no othertest flips in either direction (68 pre-existing failures, identical sets).
issue510 x5; the part_025
dirscompanions (test_dirs_redirects_stderr,test_dirs_appends_stderr) stay green.cargo fmt --checkclean.Fix A without breaking B: the #507 guard suite and the redir snapshot are
green simultaneously.