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
- X-seq: zsh-workers 55256
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: Eric Postpischil <ericpostpischil@xxxxxxxxx>
- Cc: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>, Philippe Altherr <philippe.altherr@xxxxxxxxx>, zsh-workers@xxxxxxx
- Subject: Re: BUG: Exit trap is not executed when error occurs in a function
- Date: Wed, 11 Nov 2026 05:31:28 +0100
- Arc-authentication-results: i=1; mx.google.com; arc=none
- Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=PihWNj29W031PSNyGkDlloKVrDMHFh+8/t4Ob5mMiiE=; fh=QG8ORhrdVaa4fO++KZE5fC8tPGKJqLVk8S+G2AaF1ZA=; b=mMN6zWT8GLaItX/0/AYlXPFzE31LDudmjbbO2oV+KG9iIpLoN+MnwaN/MDJlUWaGpq VdDh9XVEBZRZYTGGh02m1FuvULbUihqiJ84NSkp1sU2KtmTo1f/4y62uPMrtiHpVwAf8 xgrERZIdZew8ibwvFRZcM3YPnqh6ZlbD+/KtZk+8MYlmOhTmsgaa+7CQZDH1fvtOjwA6 MVqOUeup3BHC90xvRjnadzOwBkg2d7r4nuyFwqfvUzhQ+ajqwf8K/2sY5+q1JKj6rLlx 326mLXY7AfcCgsgDXc0Ogkx3EHAWTPkbxlXyk3Jwi2hliCIl5fOnXqdnguc9RGKmXJBC SSkA==; darn=zsh.org
- Arc-seal: i=1; a=rsa-sha256; t=1794371502; cv=none; d=google.com; s=arc-20260327; b=hfmweW8AKZ4Y4AgOCZdwzktasUS0LnEiVRtJ6VZOcvN7P8VLG6tYx50s13/1XF4lVw nZzWnFpgoZBvugFbG3mZjIi4z4niqT/59kmziPneeyKkGxyOU5rTchyxXEe4nd9Nfdth oXFfZaAn3WwfMZQBnUvSmNpAvkihBhbBc5QfIbBA6uPS1mruuo64wyx8Wnsjor7jdeNi G87tcjMJxfi2oHX1pNWLs4D6ag/I7sWSxbzJKmpBWma5+Ei72YF8dQGjpybMrfAbwZEN KG891BJg+zDhHQytCrPCBQSn0pYqDgHFj9QE6uzG3KuMfyrSqmBrYrRdayeEHO7JUej2 ihVQ==
- Archived-at: <https://zsh.org/workers/55256>
- In-reply-to: <EFF69A04-65CC-41C1-A372-5971458F35BB@gmail.com>
- List-id: <zsh-workers.zsh.org>
- References: <BCCC0361-23F4-42FD-84E2-2C4565804F3D@edp.org> <3F7FD0A9-4B81-4B88-9914-A44026F7A903@edp.org> <CAGdYchvp8S-oPE0vBgSGdBgqLgB6e+3jMcnuWwRnc-jbbS7nPw@mail.gmail.com> <CAH+w=7YKNsT2jHHxKMuJM3ANE32npfdhN_EpmSkgsan62LgEzQ@mail.gmail.com> <EFF69A04-65CC-41C1-A372-5971458F35BB@gmail.com>
On Wed, Nov 11, 2026 at 3:26 AM Eric Postpischil
<ericpostpischil@xxxxxxxxx> wrote:
>
> 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.
#!/bin/zsh -ef
setopt posixtraps
TRAPEXIT() { echo "This should be printed but is not." }
() { false }
echo "Completed function."
Someone else might be better able to explain the interaction here, but
basically without posixtraps, your TRAPEXIT is not active within the
anonymous function, and by the time the parent context would have seen
the false return and ran it before exiting, we have in fact already
exited the shell, so that never happens.
--
Mikael Magnusson
Messages sorted by:
Reverse Date,
Date,
Thread,
Author