Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Question about err_return
- X-seq: zsh-workers 41575
- From: Radon Rosborough <radon.neon@xxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: Question about err_return
- Date: Sun, 20 Aug 2017 22:28:34 -0700
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=Nzqk2QfeJ11I//2i6AuAdv7vimF2fgidaacWuuxOr+k=; b=Seh5FZVcX9H7bq2nAgKB2lyxbr/tRfWJTRn93sBsSMLSwECCKzxZD9QHGcKrV3RiHF UcSYAvCggnXM9dGTnJxdgEBAwTq0Sk7RrIyiqj9t3cTZnsWY7bFlyY5ilpzZVXfpanmq yNusf3c6Ag2sJ8X1DM0HvZXPoCeGKz614nggaOKik7aFw9RXqRZFz09Q77xHYB218EcV m7Gfh8txC1YSC/hKqNSMmiUGJOwk26qQO13DAws6iphuIOhh41PvtxDBqkkxuhsnVIAC Oy2TinoeoHtxIfxlCjBQr7+v4CbK5AF09H0wll9cPQ/EDqUCGwckR91FrSC4P/CdbMli J97Q==
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
Hi all,
I have a question about err_return. Specifically, why does the
following:
function { setopt err_return; false; echo 'oh no' }
print nothing, while
function { setopt err_return; false; echo 'oh no' } && true
prints 'oh no'? This seems very inconsistent to me, as I would expect
the result of 'x && true' to be the same as 'x' in all circumstances.
Now I found an old thread [1] about this, and the resolution was that
this behavior was unsurprising since err_return emulates err_exit. The
idea is that err_exit is automatically disabled for all child code
whenever a function is invoked as part of a conditional expression,
and so err_return does the same.
And I also found an old thread [2] on the Bash mailing list, which was
a proposal to add an err_return to Bash that would act in the way that
I expect (namely, that both examples up above would print nothing).
One of the cited advantages was that while err_exit couldn't be
changed due to backwards compatibility, its "broken" behavior could be
mitigated by a new err_return option that would work better. AFAICT,
this proposal went nowhere.
But we have an err_return in Zsh. Is it worth breaking backward
compatibility to improve the usability of err_return?
If not, I would like to know how I can otherwise implement error
checking in my scripts. I need for any unexpected error to cause an
immediate return from the enclosing function, which is how err_return
is advertised in the Zsh manual [3], but not how it actually works at
present. And preferably I would like to implement this error checking
without suffixing N hundred lines of code with '|| return $?'.
Best,
Radon Rosborough
[1]: https://www.zsh.org/mla/users/2012/msg00813.html
[2]: https://lists.gnu.org/archive/html/bug-bash/2010-05/msg00164.html
[3]: http://zsh.sourceforge.net/Doc/Release/Options.html#Scripts-and-Functions
Messages sorted by:
Reverse Date,
Date,
Thread,
Author