zsh-workers
 help / color / mirror / code / Atom feed
* Question about err_return
@ 2017-08-21  5:28 Radon Rosborough
  2017-08-21  6:27 ` Daniel Shahaf
  2017-08-23 16:56 ` Peter Stephenson
  0 siblings, 2 replies; 5+ messages in thread
From: Radon Rosborough @ 2017-08-21  5:28 UTC (permalink / raw)
  To: zsh-workers

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-08-24 10:41 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-21  5:28 Question about err_return Radon Rosborough
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

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).