You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix EXIT trap not firing when ERR_EXIT or ${var:?} triggers inside a function
When ERR_EXIT triggers inside a function, the errexit code path
called realexit() directly, bypassing endtrapscope() and skipping
any EXIT traps saved by starttrapscope() on function entry.
Similarly, when ${var:?message} triggers inside a function, the
paramsubst code path called _exit(1) or zexit() directly,
bypassing the function unwind and skipping EXIT traps at outer
scopes.
Reuse the same exit_pending unwind mechanism as the exit builtin,
so that endtrapscope() runs at each function level and all nested
EXIT traps are executed bottom-up, matching the behaviour of an
explicit exit call.
Extract set_exit_pending() to consolidate the repeated unwind
setup (trap_state, retflag, breaks, exit_pending, exit_level,
exit_val) used by the exit builtin, the ERR_EXIT handler, and
the new ${var:?} handler.
Extract restore_saved_trap() from endtrapscope() to reduce
duplication in the trap restoration logic.
Clear errflag in endtrapscope() when exit_pending, so that
EXIT traps can fire even when the exit was triggered by an error
(e.g. ${var:?}). This mirrors what zexit() already does before
calling dotrap(SIGEXIT).
0 commit comments