Skip to content

Commit

Permalink
interp: make trap consistent with errexit logic
Browse files Browse the repository at this point in the history
This implementation already excludes conditional contexts
for exiting on error when errexit is set; it should be
consistent with reporting errors to a trap routine.
  • Loading branch information
reubeno authored and mvdan committed Dec 5, 2022
1 parent 289e21b commit 8472ca4
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
1 change: 1 addition & 0 deletions interp/interp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2156,6 +2156,7 @@ set +o pipefail
// trap
{"trap 'echo at_exit' EXIT; true", "at_exit\n"},
{"trap 'echo on_err' ERR; false; echo FAIL", "on_err\nFAIL\n"},
{"trap 'echo on_err' ERR; false || true; echo OK", "OK\n"},
{"trap 'echo at_exit' EXIT; trap - EXIT; echo OK", "OK\n"},
{"set -e; trap 'echo A' ERR EXIT; false; echo FAIL", "A\nA\nexit status 1"},
{"trap 'foo_interp_missingbar_interp_missing' UNKNOWN", "trap: UNKNOWN: invalid signal specification\nexit status 2 #JUSTERR"},
Expand Down
2 changes: 1 addition & 1 deletion interp/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ func (r *Runner) stmtSync(ctx context.Context, st *syntax.Stmt) {
// part of && or || lists
// preceded by !
r.exitShell(ctx, r.exit)
} else if r.exit != 0 {
} else if r.exit != 0 && !r.noErrExit {
r.trapCallback(ctx, r.callbackErr, "error")
}
if !r.keepRedirs {
Expand Down

0 comments on commit 8472ca4

Please sign in to comment.