zsh-workers
 help / color / mirror / code / Atom feed
From: Radon Rosborough <radon.neon@gmail.com>
To: zsh-workers@zsh.org
Subject: Question about err_return
Date: Sun, 20 Aug 2017 22:28:34 -0700	[thread overview]
Message-ID: <CADB4rJG_ajfBdeC+Cd4YHDhi2pXRr3j7tCXKrV_AvT6+Y7_U7A@mail.gmail.com> (raw)

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


             reply	other threads:[~2017-08-21  5:29 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-21  5:28 Radon Rosborough [this message]
2017-08-21  6:27 ` Daniel Shahaf
2017-08-23 16:56 ` Peter Stephenson
2017-08-23 20:09   ` Peter Stephenson
2017-08-24 10:33     ` Peter Stephenson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CADB4rJG_ajfBdeC+Cd4YHDhi2pXRr3j7tCXKrV_AvT6+Y7_U7A@mail.gmail.com \
    --to=radon.neon@gmail.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).