Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: BUG: Exit trap is not executed when error occurs in a function



On Nov 10, 2026, at 21:07, Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:

> I think this is DMARC related, edp.org has a p=reject policy which is
> tripped when zsh-workers forwards the email without changing the From:
> header.

Thanks, I have switched to a Gmail account.

> I haven't dug in myself but I think this is actually expected
> behavior?  Return from a function is not a shell exit?  There should
> be some archive messages related to the handling of ERR_EXIT vs.
> ERR_RETURN.

Well, the script did terminate, so at some point, the shell did exit, yet the exit handler was not executed. Whatever path is taken with regard to the function, exiting from it with an error or continuing to its end and return, the script eventually does exit, so the exit handler should be called, yes?

If we execute this:

#!/bin/zsh -ef
TRAPEXIT() { echo "This should be printed but is not." }
() { false }
echo "Completed function."

Then “Completed function” is not printed. That lack indicates the function did not return normally; execution of the script was terminated without continuing after the function execution.

				— edp (Eric Postpischil)
				https://edp.org





Messages sorted by: Reverse Date, Date, Thread, Author