From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,HTML_MESSAGE,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=3.4.4 Received: from zero.zsh.org (zero.zsh.org [IPv6:2a02:898:31:0:48:4558:7a:7368]) by inbox.vuxu.org (Postfix) with ESMTP id 02022268FE for ; Wed, 26 Jun 2024 14:43:26 +0200 (CEST) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1719405806; b=RQK/86NP56brxQCpfIsPJl1J6clEGkkm88BoNGiyH+2jHyQ5/sIJvrL+s4ZkGrwR/Y/VKAsUH0 cIV3jIyp8EhZqiMoqDcvfhEZ5j1XRzZ4o281uueg9/xJvc5B6W3V0UoSW6H5ljVMzMjTcNoFXj dzlmEE8p2QhQUhK9db0rt9+uNoWhfRPMNV2K2XiOV5rn4DdCK6UVM/sRAWf21lzYIoCe34n4wg aIme/2OiFV/2jQbsuWJg6aVUhc2yfHAukh+CGgmNoeEj6tPlzUbw7lGNliTd2qFpHvdnlDRWMN ZnZNPsmNew7A43yybmyznzHVC+PPs8FrMsOHCvbx6vFDnQ==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-lf1-f53.google.com) smtp.remote-ip=209.85.167.53; dkim=pass header.d=gmail.com header.s=20230601 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1719405806; bh=dt1k/ibvV81dH85EM6YuTzdjpxqrqlT+pMflYMgpWo0=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Type:Cc:To:Subject:Message-ID:Date:From:In-Reply-To: References:MIME-Version:DKIM-Signature:DKIM-Signature; b=JJu4LFHPHkLca+cTvaY8uInxaQXaPa8Y02bEVjfSEMNl7eWrO/Bw1HZmK2oHHhP1bO6TYQ9Cyf WY0yz3KwmJJqAqhz+RCeiW7Jip/hpyJwpE1u6Q1wB23M+mvI605sV/6WbKGGR9l+Sm33e/JhrU IfN7K8xtVS3KN6NJORfRb+v7f+oUahzQIGJJIyd+Ba9QTkIC7xJ9SiP/oE3tTmqw2qctwC4JSb bcO5tM+CAGdXF1sks2OCMztjYbStae6DzVAGKsXW3G/Tyq+PA6MGdHsblygCYfR/Wm18HMqDP9 LgOdWmigt8NX+JiZfAqAfAPqIJ3l9UL7xy4fQczIvp4jXA==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Type:Cc:To:Subject:Message-ID :Date:From:In-Reply-To:References:MIME-Version:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=+HBGBqyx7FuI4wMh7dHelxMrKNVoXzQNpF6b115+g2M=; b=oduEExPCrlRIQFuheR0By87zQy f+5tUqJ2xVCzhAPsTBLFgEOwxVykbDRkBsV/bAgO8qgrRMZHHduiiBirxnG1y4PKakikRjKDAbAML wBkolivDpwpwNyPHABZ51jyPyNAX8pVb+F39bbzdNkmRnySr5GOzqS7f+mD1YqG/IOSvcavGXNYEq AsurCG9+RaIbZ4DnD4ouFPOS9E0GGBs07Z1rg3vq3MC2CNoW+WyrF1yqIxkSygAJJBWt8xdwQnyW1 I5y1eTZNvsv1J5i3aNWIeQ0BBl8wFEmsMqNTiR6uBbti5QDhbKrlfcaq8TDTOpgDXGu0GRMQu7tRS QR1MIAFA==; Received: by zero.zsh.org with local id 1sMRzh-000J16-Cp; Wed, 26 Jun 2024 12:43:25 +0000 Authentication-Results: zsh.org; iprev=pass (mail-lf1-f53.google.com) smtp.remote-ip=209.85.167.53; dkim=pass header.d=gmail.com header.s=20230601 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none Received: from mail-lf1-f53.google.com ([209.85.167.53]:52267) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1sMRzH-000Iih-TA; Wed, 26 Jun 2024 12:43:01 +0000 Received: by mail-lf1-f53.google.com with SMTP id 2adb3069b0e04-52cd80e55efso8863470e87.0 for ; Wed, 26 Jun 2024 05:42:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719405779; x=1720010579; darn=zsh.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=+HBGBqyx7FuI4wMh7dHelxMrKNVoXzQNpF6b115+g2M=; b=bFwFiDGJOx7o36SN88WBfdEDoaCSr8UVEC4iOaQl2RUGOn5EWprKuLfX6+uphoOxik jpPWZ/o79fxgqCrseZEGf05+pT5ADHRHwpRaWg/vcn7Ds3YwJW6brb5BKYae0VdP/7K0 BlKn6m8+LK06c/oHCLBHLjPD4t/rXUsOUAczSBX2CvIFu8SE8tDGTkKhVUomEp4eTNC4 b8YMDbC5FmDPjX25yMTxtCtawLzAJIEfkqou79Gb3hbCzPeHX72JOy71pzsVfKDqy234 AKbU6bzDtIWplwtM4L8ZiKCxEIs32gL57HWZt5/7j9ix5LvfcbTfMy6No74eMf9q5gQk DieA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719405779; x=1720010579; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=+HBGBqyx7FuI4wMh7dHelxMrKNVoXzQNpF6b115+g2M=; b=sit4maxK+a2n8sP9S++qHID4bv9VDNfWnRoUdWsQjoP6hsLp+VChnoOy6wuFApuazL 45R7PSzuq7DCaynMuj2IzIO/MZPDXPrDhoJDp3IaNXOHVq0Vx5i1YzDa+7vZfx7eviGN kUmgpt3hEExp5YuHdqGVaY573KFi/jH9jXt0NNnx9ITSZtgco0onj6kxnVC3R4xJqdq2 h7MxvKPj++i123ZEfDzoZKXOfVUiERP6tQPAVaRRsmfTBbx5flxIZJPvkxeP96vFrETP V9B2RLzw37NLlwvnBj1u+jIZOKqJbj/lLxOJLYmJdYvRqVtP9bUY9th91xKHr48psDcE tebg== X-Gm-Message-State: AOJu0YzM0HWOLCuTFSWfYR8w52PWNFe5vqaGCT8ACT3HopXjB2XR587E mESgt8+le7aUh10zWt7iMT9Jwt52VulCHJbQ75LqT10UQDLVtNCA0ngRjFYDgOoRWbOYRulI2n5 cTglQBu05Le1uAqA57lFjFGeJ3ESh0j4K X-Google-Smtp-Source: AGHT+IH4A78nG4Cu5HcYpqQyS0GnBs1LVSUXVN11PN+7LsScjXVpx8KuQ73JoRNlyFU0Pi2100MxkI/5oZsevT7Cp4c= X-Received: by 2002:a05:6512:3484:b0:52c:dcec:e563 with SMTP id 2adb3069b0e04-52ce1832b29mr7037154e87.21.1719405778730; Wed, 26 Jun 2024 05:42:58 -0700 (PDT) MIME-Version: 1.0 References: <5d54375e-8673-45f0-b5ac-f5e0e233d56f@inlv.org> <2a5f0fa7-23bf-4069-b237-d304965f142e@app.fastmail.com> <33ca21c3-69f8-49f7-9350-2ff9cc4febca@app.fastmail.com> In-Reply-To: From: Philippe Altherr Date: Wed, 26 Jun 2024 14:42:46 +0200 Message-ID: Subject: Re: errexit and (Z)ERR trap regression To: Bart Schaefer Cc: zsh-workers@zsh.org Content-Type: multipart/mixed; boundary="000000000000ab3a44061bca5aa8" X-Seq: 52975 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: , List-Subscribe: , List-Unsubscribe: , List-Post: List-Owner: List-Archive: --000000000000ab3a44061bca5aa8 Content-Type: multipart/alternative; boundary="000000000000ab3a43061bca5aa6" --000000000000ab3a43061bca5aa6 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Note that just adding braces is enough to trigger the bug: $ zsh -e -c 'true && false; echo NOT REACHED' # no output; correct $ zsh -e -c 'true && {false; echo NOT REACHED}' # incorrect output NOT REACHED and $ zsh -c 'trap "echo Trapped!" ERR; true && false' # correct outpu= t Trapped! $ zsh -c 'trap "echo Trapped!" ERR; true && {false}' # no output; bug I think that the correct fix is the following: if (isandor || isnot) noerrexit =3D oldnoerrexit | NOERREXIT_EXIT | NOERREXIT_RETURN; else noerrexit =3D oldnoerrexit; For reminder, here is the current code: if (isandor || isnot) noerrexit |=3D NOERREXIT_EXIT | NOERREXIT_RETURN; In other words, every sub-command in a list should only depend on the noerrexit that was in effect at the start of the evaluation of the list. It should in no way depend on the noerrexit that results from the evaluation of proceeding sub-commands as is currently the case. The current code only works for lists where the last sub-command is a simple command, thanks to the "noerrexit =3D oldnoerrexit;" performed after the last sub-command just before checking whether an ERREXIT should be triggered. Here are two other examples fixed by this patch: zsh -c 'trap "echo Trapped!" ERR; true && if true; then false; fi' zsh -c 'trap "echo Trapped!" ERR; true && {false} always {true}' Philippe On Tue, Jun 25, 2024 at 1:03=E2=80=AFAM Bart Schaefer wrote: > On Fri, Jun 21, 2024 at 10:50=E2=80=AFPM Lawrence Vel=C3=A1zquez > wrote: > > > > > set -e; true && { false; echo one; } || echo two > > > > > > Is "false" there considered to be "any command of an AND-OR list" ? > > > > This ought to work the same as the subshell version: early exit is > > suppressed for the commands "true" and "{ false; echo one; }", so > > the overall output is still "one". > > The following seems to fix all six of the mentioned cases from this > thread, then. > --000000000000ab3a43061bca5aa6 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Note that just adding braces is enough to trigger the= bug:

=C2=A0 =C2=A0 =C2=A0$ zsh -e -c 'true &&a= mp; false; echo NOT REACHED'=C2=A0 =C2=A0 =C2=A0# no output; correct=C2=A0 =C2=A0 =C2=A0$ zsh -e -c 'true && {false; echo NOT REAC= HED}' =C2=A0# incorrect output
=C2=A0 =C2=A0 =C2=A0NOT REACHED
and

=C2=A0 =C2=A0 =C2=A0$ zsh -c 'trap "echo Trapped!&quo= t; ERR; true && false' =C2=A0 =C2=A0 # correct output
=C2=A0= =C2=A0 =C2=A0Trapped!
=C2=A0 =C2=A0 =C2=A0$ zsh -c 'trap "echo= Trapped!" ERR; true && {false}' =C2=A0# no output; bug

I think that the correct fix is the following:

=C2=A0 =C2=A0 if (isandor || isnot)
=C2=A0 =C2= =A0 =C2=A0 =C2=A0 noerrexit =3D oldnoerrexit | NOERREXIT_EXIT | NOERREXIT_R= ETURN;
=C2=A0 =C2=A0 else
=C2=A0 =C2=A0 =C2=A0 =C2=A0 n= oerrexit =3D oldnoerrexit;

For reminder, here is t= he current code:

=C2=A0 =C2=A0 if (isandor || isno= t)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 noerrexit |=3D NOERREXIT_EXIT | NO= ERREXIT_RETURN;


In other words, eve= ry sub-command in a list should only depend on the noerrexit that was in ef= fect at the start of the evaluation of the list. It should in no way depend= on the noerrexit that results from the evaluation of proceeding=C2=A0sub-c= ommands as is currently the case. The current code only works for lists whe= re the last sub-command is a simple command, thanks to the "noerrexit = =3D oldnoerrexit;" performed after the last sub-command just before ch= ecking=C2=A0whether an ERREXIT should be triggered.

Here are two other examples fixed by this patch:

=C2=A0 =C2=A0 zsh -c 'trap "echo Trapped!" ERR; true &&a= mp; if true; then false; fi'=C2=A0
=C2=A0 =C2=A0 zsh -c '= trap "echo Trapped!" ERR; true && {false} always {true}&#= 39;=C2=A0

Philippe



On Tue, Jun 25, 2024 at 1:03=E2=80=AFAM Bart Schaefe= r <schaefer@brasslantern.co= m> wrote:
On Fri, Jun 21, 2024 at 10:50=E2=80=AFPM Lawrence Vel=C3=A1zquez <larryv@zsh.org> wrote= :
>
> >=C2=A0 =C2=A0 set -e; true && { false; echo one; } || echo= two
> >
> > Is "false" there considered to be "any command of = an AND-OR list" ?
>
> This ought to work the same as the subshell version: early exit is
> suppressed for the commands "true" and "{ false; echo o= ne; }", so
> the overall output is still "one".

The following seems to fix all six of the mentioned cases from this
thread, then.
--000000000000ab3a43061bca5aa6-- --000000000000ab3a44061bca5aa8 Content-Type: text/plain; charset="US-ASCII"; name="noerrexit-list-subcommands.txt" Content-Disposition: attachment; filename="noerrexit-list-subcommands.txt" Content-Transfer-Encoding: base64 Content-ID: X-Attachment-Id: f_lxvtnjpa0 ZGlmZiAtLWdpdCBhL1NyYy9leGVjLmMgYi9TcmMvZXhlYy5jCmluZGV4IGU5NTVlODVkZi4uOTE2 YTM1NjdkIDEwMDY0NAotLS0gYS9TcmMvZXhlYy5jCisrKyBiL1NyYy9leGVjLmMKQEAgLTE0ODUs NyArMTQ4NSw5IEBAIGV4ZWNsaXN0KEVzdGF0ZSBzdGF0ZSwgaW50IGRvbnRfY2hhbmdlX2pvYiwg aW50IGV4aXRpbmcpCiAJICAgIG5leHQgPSBzdGF0ZS0+cGMgKyBXQ19TVUJMSVNUX1NLSVAoY29k ZSk7CiAJICAgIC8qIHN1cHByZXNzIGVycmV4aXQgZm9yIGNvbW1hbmRzIGJlZm9yZSAmJiBhbmQg fHwgYW5kIGFmdGVyICEgKi8KIAkgICAgaWYgKGlzYW5kb3IgfHwgaXNub3QpCi0JCW5vZXJyZXhp dCB8PSBOT0VSUkVYSVRfRVhJVCB8IE5PRVJSRVhJVF9SRVRVUk47CisJCW5vZXJyZXhpdCA9IG9s ZG5vZXJyZXhpdCB8IE5PRVJSRVhJVF9FWElUIHwgTk9FUlJFWElUX1JFVFVSTjsKKwkgICAgZWxz ZQorCQlub2VycmV4aXQgPSBvbGRub2VycmV4aXQ7CiAJICAgIHN3aXRjaCAoV0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