From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.3 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, FREEMAIL_FROM,MAILING_LIST_MULTI,NICE_REPLY_A,RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 18527 invoked from network); 11 Nov 2022 04:09:55 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 11 Nov 2022 04:09:55 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1668139795; b=CLHl8RQkWdmB9nr1CyLpnL/AmH/iIbSkaiUXXWoX8wkK0rD/zfLajPH/pHARUKimOXXIsWL2D1 gDEzftDS6hEKyuaeIC2B2g9mm7n2rJFPfXm8BF3KAY/cExfvzcwx2WpqKShZAz0cmL6mbL16rB qlN7U+Kk5GSgopRtgzOIdHlE835ewcnb93WXHHYaTq4qfhZp54lcxnqaESQX2V/s66weHDMIFj PybFkeXF5p9xyrorOf2qqehE3VA0NU7VF8jh4Lg8Z9rdfZypJ0rYLiagppQtnIlVijBRaQbZBm azr7iV48RZTbGXSMb+orNAYi/RggSi2Vu90tdZey2UXvmg==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mout.gmx.net) smtp.remote-ip=212.227.17.20; dmarc=none header.from=gmx.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1668139795; bh=06klMjz2FzfWbT3tIYteovVkP0RlCBMtJGcrTtaMq6I=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Transfer-Encoding:Content-Type:In-Reply-To:From: References:To:Subject:MIME-Version:Date:Message-ID:DKIM-Signature; b=oyQoWYWtpis38dH7RGMdyNjrOo9n3ZjpbYAL2fxGfLlzYjrgL1iKPgWln1AYeJhduPglbAFxe+ hVICeAWycvNH/fzkwJUxq9dCSUrw0/BRB9lpJlHeteukLPeQwLkWtRVj1BA9h0QTVgn3RoTXcx KpTDnswaJwXEsFJcstLSmRyi7qmetQHWPWFKlVv9m3kJy98x36sjbPIfvjhjbarZUPfoMx8Guq t6LqPRm//6Kw7GCdh1XIRJ4NFQRf5YT5WUYZKcOUVrakNhMnhSui81gnR6/L5JP6zMzN2+Pu8u /Nq0ekPZl70lODO5S/Pe/HTl9HDBmWVrVARh42xwQWT48Q==; 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-Transfer-Encoding: Content-Type:In-Reply-To:From:References:To:Subject:MIME-Version:Date: Message-ID:Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From :Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=M+6qQBYDysU0XFGPSuVoGqhR9Ic6Jdr1nXtTQS+Y0pc=; b=MLt4NOH7MfpLqthArq2ndxWbEq 6Fhz/63sQHlnPC/fDl3DXjSvBczUz5H80rHG99c5eGS5UEQC0lstTKXxAKVsvM2oGRdDbmsJzt+Jb 2WIowYl2r1zcJrPbJBS7Ow2p/tFWgoQroF5Rl6aR9VpCf5WQZLKKmG5y5dkJI9XyW/gUXuXCbB6Sw 6t+iUq4XLdM/DBGZUD4EGrkgm+srQuPlGuDfr2CEpDGY6ILv9cxkthh8zE3+E0hbmMKYU+K1PNRVG AqseDA4rft56DKGwYxYNR7brfLQnV7dYe0M/MlExC+MOE2wzNUcckWaBh7w7nUegyEKuQMvUUe58b oY30seXw==; Received: by zero.zsh.org with local id 1otLMZ-0006H1-FM; Fri, 11 Nov 2022 04:09:55 +0000 Authentication-Results: zsh.org; iprev=pass (mout.gmx.net) smtp.remote-ip=212.227.17.20; dmarc=none header.from=gmx.com; arc=none Received: from mout.gmx.net ([212.227.17.20]:59831) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1otLLp-0005v5-FO; Fri, 11 Nov 2022 04:09:10 +0000 Received: from [10.0.0.14] ([71.227.85.179]) by mail.gmx.net (mrgmx104 [212.227.17.174]) with ESMTPSA (Nemesis) id 1Mq2jC-1pObQc1ozi-00n6qA for ; Fri, 11 Nov 2022 05:09:08 +0100 Message-ID: <9804c915-29ea-1ee1-e8e5-638c76ee4fa4@gmx.com> Date: Thu, 10 Nov 2022 23:09:07 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.1 Subject: Re: Inconsistent behavior of ERR_EXIT with conditionals To: zsh-workers@zsh.org References: <1edb7786-f0b2-4830-88fa-99a19bda39e2@app.fastmail.com> Content-Language: en-US From: Eric Cook In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Provags-ID: V03:K1:LIh+RzvPqIHhLfglRdZBucToP8Zqp6qUAaNe8E6MpNre21RXp9K oP/UqflQP28jwsQJL7gH0HqgRvOHcDgGXuohokvqmITydW752Oie4X5SQxjZdIBYZkuC0/B /06RtbCrDJqin7Jd/INryuj3qY5JzkBCPC/6zvko5euvYE3GzSxGxij2WLFBd9UFB22mWUu ksqRVX6HmBEVlNHb1kfVw== UI-OutboundReport: notjunk:1;M01:P0:JDCl0etBWqk=;ooSGrMo02NplujM9VfXauQRmaGU XBAY9uKlI290MjbdbutLA4XZt1YJO5Oz9JfAJBa2jkMYySdX3/5PtBkn3FmufpohfES0G1Qgq pNga9dVlXmCAoDmpKze2e7AsM/5yiP+PKB0qL2+vo6L1VH8dyyw/fHjdedRaUiRnBFxDe92GR wuRfdhX0fCHQ/lCSh7EKVAVn6cs5UqHY5AuJ9eJkeLqeqqWXeaUsckWWkwHyjda2uOC3IiwCD osweZWdN1ayD8KHYQX3FAMPbqfdgYzSxfkCNiObPIOAMaUvt7/mA/hs7KdiFgUtuAa8r7m/vq l6CdQjZVkBrvaUAeKU0HQi2tc7THwlVY7r9VBdMduwnpYdXHeCdgT3KbgrOq0WRXwIF4fuSnT 2T08hKqpcc5jVjqvCgTu7JmE7kPgwA7cMhhW3f45TVzdQgX0Qf2aFHMx5Y74lPuS7Vi48dX8b vJpvW+bMaAfaua8cN+ZfUd4mbrloPHvV8P4mr37gycOZiex6yqbgUDgsbgAeocyQV1fkXpmA2 MeqB+8N+fOnAfv2jN90umC/5coFTr044UDHUjHbTdLvTvFc1S7MFmh6uUnyYT4ZleThITWTTi 953LIz2uk0XipOXoLENH+UNJ3enuzyXpAXvhSBUcgUBR9Z6q3gV/h/NW5wUBbWuoYEHBfG0/o F7GWvq+nhEwpWSqnIy+rYVv7uTjeE+4qlhA0g3zOIblvAcg7cHPJsPuQvZ6aSMI71uv/1PlM7 CF3DkEh5hcWkjzGAzO1esjgY6AJrxME7EvC0tyFi1gwaERH3l9hICg3U9nqmzw3UhrY7N5miE +bu5qN/afbDSFI0gXjMkRmaIwm3syinCL56TpSaHYARrZCNDmMKll0RDd2l0+F9jOSuD3tGjI WzLA/jJ/BRHpvm2hteqc7WVy77sQPaWyUWKJa3rKbSh/z7w702qH7oe3EG6qHjYOF7BwAa7ES 2HHgtWHWo5mYgITusMiOIVd1aws= X-Seq: 50939 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: On 11/10/22 22:04, Philippe Altherr wrote: > I'm mainly a Java developer. In Java many functions may throw runtime exceptions. You can catch and handle these but in 99% of the cases you just ignore them because you know (or assume) that they won't be thrown. Doing otherwise would be very impractical > because your code would be littered with try/catch statements. Every now and then one of these exceptions that you thought could/should never be thrown is nevertheless thrown for some reason. In that case the exception goes up the call stack and, if no > catch is encountered, it kills the program and prints a stack trace to the code that threw the exception. This way it's obvious that something failed. It's also easy to figure out where it happened. And, it ensures that no extra harm is done (by keeping > running the program). > > In the world of shell scripts, there are no runtime exceptions but some exit statuses play a similar role. Many UNIX commands and shell functions can potentially return a non-zero exit status but when you use them you often know (or assume) that they > won't return a non-zero exit status. If they nevertheless do, the default behavior of shell script is to simply ignore the error. So if "cmd1" fails in "cmd1; cmd2", "cmd2" still gets executed. It's already bad that "cmd1" failed. Running "cmd2" could > cause extra harm. It looks much safer to exit right after "cmd1". That's the main reason I run all my scripts with ERR_EXIT enabled. > > In addition to that, ERR_EXIT also makes it easier to notice errors and to figure out where they happened, especially if ERR_EXIT is coupled with code that prints a stack trace. Without ERR_EXIT you may not even notice that something went wrong if no > error message was printed (or it got swallowed). > > My impression is that ERR_EXIT is commonly used for these reasons. In fact, whenever I have seen it used, it seemed to be for these reasons. But maybe I should confirm that. I'll ask some of my friends if they use it and with what expectations. Didn't read the entire thread but the first quoted paragraph seems to be the commonly misguided reason to blindly use set -e; attempting to use a paradigm of a language more familiar to the author, to a different language. As more and more people start their programming careers in languages with exceptions, exception-less languages like unix shells[1] or more recently go-lang[2] looks pretty antiquated. > In my opinion, the only downside of that usage of ERR_EXIT is that it's far from foolproof. There are plenty of cases where just enabling ERR_EXIT won't be enough to ensure that the script halts at the first unexpected error. Correct, it is far from foolproof and it can create additional problems when it unexpectedly unexpected errors and terminate the script for reasons that can confuse the author. [1] [1] http://mywiki.wooledge.org/BashFAQ/105 [2] https://go.dev/doc/faq#exceptions