Repository navigation
WIP: fix(traps): no ERR adjudication for an exit unwind (#2482 t133 residual) - #2512
Merged
Merged
Conversation
…t133) GNU's run_error_trap call sites (execute_cmd.c:773/1000/1166/2909) only ever adjudicate a command that completed with a status; the exit builtin never returns one — builtins/exit.def exit_or_logout ends in jump_to_top_level (EXITBLTIN), and run_exit_trap (trap.c:1027) catches that jump with its own setjmp, so no frame the unwind crosses performs failure adjudication for an exit-terminated chain. execute_materialized_command's errexit tail fired maybe_run_error_trap whenever exit_code was nonzero under live errexit, including for an in-flight Err(ExitCode): once at the exit builtin's own dispatch frame (`set -eET; trap .. ERR; exit 1` fired in rubash, silent in GNU), and again at eval/source wrapper frames whose inner command had already been adjudicated (`eval 'false'` fired twice). In the bats cell-133 shape the extra fire re-ran bats_error_trap inside the EXIT teardown chain, printing a second raw "failure callback" line. Gate the tail's fire on result.is_ok() — the same rule the branch's conversion mark already applies (only an Ok completion is converted). In-flight unwinds propagate unchanged. Stacked on PR #2506 (fix/2482-2484-trap-stream), whose face-a/b trap machinery this adjudication sits in. Verification (GNU bash 5.3.20, script files): 33 probe shapes count-compared, core shapes byte-identical (exit chains in the body / EXIT action / eval / source / subshell / pipeline stage, plus ordinary-failure controls). New pins tests/issue2482_t133_err_retrigger.rs 16/16; #2506 pins 8/8 + 8/8; issue2212 15/15; adjacent trap/errexit targets all green. mini2212_t133.bats: ok, TAP identical to GNU (was not ok on the #2506 tip). Refs #2482
caomengxuan666
force-pushed
the
fix/2482-t133-err-retrigger
branch
from
November 1, 2026 19:15
4a4fb3f to
664fd86
Compare
caomengxuan666
changed the base branch from
fix/2482-2484-trap-stream
to
master
November 1, 2026 19:15
caomengxuan666
marked this pull request as ready for review
November 1, 2026 19:32
Member
Author
|
[win-acceptance] #2512 PASS — pin Environment: Windows 10 19045 real machine, MSVC Rust debug build of master 9348b8d (contains this merge). No BLOCKER. |
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.
Refs #2482 — the t133 residual left open by #2506: inside the EXIT
trap action, a command chain terminated by an inner
exitfiredthe ERR trap a second time (bats printed a duplicate raw
failure callbackline; mini2212_t133 stayed red).Stacked on #2506 (
fix/2482-2484-trap-stream@ 8d51e7f) —this PR's base is that branch; it carries exactly one commit on
top and should merge after / be rebased with #2506.
GNU law (vendored bash-5.3 source)
run_error_trapis called only from execute_cmd.c:773/1000/1166/2909, always for a command that completed with a status. The
exitbuiltin never completes: builtins/exit.defexit_or_logoutends in
jump_to_top_level (EXITBLTIN), andrun_exit_trap(trap.c:1027) installs its own
setjmp(top_level)to catch it —so no frame the unwind crosses adjudicates the chain. Ordinary
failures inside trap actions adjudicate exactly like anywhere
else (no
running_trapgate at any site), and anexitinside asubshell / pipeline element is an ordinary failure of that
subshell command in the parent.
Truth table (GNU 5.3.20, script files; ERRFIRE counts):
h→g→exit 1, -eETexit 3h→g→exit 1exit 1/{ exit 1; }eval 'exit 1'/. src(exit)eval 'false'/. src(false)( exit 1 )( exit 1 )statementtrue | gin action (g exits)Defect site
execute_materialized_command's errexit tail (command_dispatch.rs)fired
maybe_run_error_trapfor any nonzeroexit_codeunder liveerrexit — including an in-flight
Err(ExitCode):exitbuiltin's own dispatch frame (attribution probes:the fire carries the exit node's own line), and
already been adjudicated and converted (
eval 'false'firedtwice,
. src(false)fired twice).Function-call frames never re-fired: the funnel's function fast
path (command_execute.rs
execute_function_command_invocation)bypasses this tail, which is why the extra count was exactly one
per chain.
Fix
One gate: the tail fires only when
result.is_ok()— the samerule the branch's own conversion mark already states ("mark ONLY
the conversion of an Ok completion — an Err already in flight
stays unmarked"). In-flight unwinds propagate byte-identically;
nothing in the session/subshell exit machinery changes.
Verification
core shapes (x4/x5/x8/x10/x13/x17/x18/x22,
( exit 1 ))byte-identical including exit codes.
tests/issue2482_t133_err_retrigger.rs: 16/16(incl. the bats-mini distillation and boundary guards).
err_trap_pipeline 8/8; issue2212 remainder 15/15.
(eval/source frames) 13/13, issue1611 11/11, issue1661 12/12,
issue1012 8/8, issue1542 7/7, issue1162-1166 4/4,
issue1278 2/2, issue1405 2/2, issue1171 1/1 (scrubbed runs).
mini2212_t133.batsunder the fixed binary —ok 1, TAP byte-identical to GNU (was
not okon the WIP: fix(traps): #2482 fatal-unwind stack + ERR-in-pipeline (faces a/b); #2483/#2484 analysis #2506tip); the inner suite output no longer carries the duplicate
raw
failure callbackline.