zsh-workers
 help / color / mirror / code / Atom feed
* New problem with ERR_RETURN ?
@ 2022-12-07 16:17 Bart Schaefer
  2022-12-07 16:37 ` Peter Stephenson
  2022-12-07 16:41 ` Philippe Altherr
  0 siblings, 2 replies; 9+ messages in thread
From: Bart Schaefer @ 2022-12-07 16:17 UTC (permalink / raw)
  To: Zsh hackers list

After zsh-workers 51001, 51071, 51076 (Philippe A.)

This seems wrong:

% setopt errreturn
% f() {
    while return 5
    do
        echo fail while1
        break
    done
}
% f ; echo $?
%

Note that "echo $?" was not executed when it appears in the same
command line as "f".  I don't believe ERR_RETURN should be having an
effect there.

Compare:

% f
% echo $?
5
%


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

* Re: New problem with ERR_RETURN ?
  2022-12-07 16:17 New problem with ERR_RETURN ? Bart Schaefer
@ 2022-12-07 16:37 ` Peter Stephenson
  2022-12-07 16:41 ` Philippe Altherr
  1 sibling, 0 replies; 9+ messages in thread
From: Peter Stephenson @ 2022-12-07 16:37 UTC (permalink / raw)
  To: Bart Schaefer, Zsh hackers list

> On 07/12/2022 16:17 Bart Schaefer <schaefer@brasslantern.com> wrote:
> After zsh-workers 51001, 51071, 51076 (Philippe A.)
> 
> This seems wrong:
> 
> % setopt errreturn
> % f() {
>     while return 5
>     do
>         echo fail while1
>         break
>     done
> }
> % f ; echo $?
> %
> 
> Note that "echo $?" was not executed when it appears in the same
> command line as "f".

I haven't had a chance to look but I'm guessing this is something
along the lines of not properly restoring the "breaks" variable when
we return from the function, or some equivalent lack of care
with "retflags".

pws


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

* Re: New problem with ERR_RETURN ?
  2022-12-07 16:17 New problem with ERR_RETURN ? Bart Schaefer
  2022-12-07 16:37 ` Peter Stephenson
@ 2022-12-07 16:41 ` Philippe Altherr
  2022-12-07 16:53   ` Peter Stephenson
  2022-12-07 16:58   ` Bart Schaefer
  1 sibling, 2 replies; 9+ messages in thread
From: Philippe Altherr @ 2022-12-07 16:41 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Zsh hackers list

[-- Attachment #1: Type: text/plain, Size: 1030 bytes --]

I don't think there is a problem. At least not a new problem because Zsh
5.8 and Zsh dev behave the same way.

Note that if you replace the body of "f" with just "false" you get the same
results.

Note also that if you run "return; echo $?" nothing is printed.

From that I concluded that the example behaves correctly. The function "f"
returns a non-zero status. Therefore the call to "f" triggers a return,
which at the top-level simply exits the script/returns to the command line
and thus bypasses what comes next.

Philippe


On Wed, Dec 7, 2022 at 5:17 PM Bart Schaefer <schaefer@brasslantern.com>
wrote:

> After zsh-workers 51001, 51071, 51076 (Philippe A.)
>
> This seems wrong:
>
> % setopt errreturn
> % f() {
>     while return 5
>     do
>         echo fail while1
>         break
>     done
> }
> % f ; echo $?
> %
>
> Note that "echo $?" was not executed when it appears in the same
> command line as "f".  I don't believe ERR_RETURN should be having an
> effect there.
>
> Compare:
>
> % f
> % echo $?
> 5
> %
>
>

[-- Attachment #2: Type: text/html, Size: 1602 bytes --]

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

* Re: New problem with ERR_RETURN ?
  2022-12-07 16:41 ` Philippe Altherr
@ 2022-12-07 16:53   ` Peter Stephenson
  2022-12-07 17:02     ` Bart Schaefer
  2022-12-07 16:58   ` Bart Schaefer
  1 sibling, 1 reply; 9+ messages in thread
From: Peter Stephenson @ 2022-12-07 16:53 UTC (permalink / raw)
  To: Zsh hackers list

> On 07/12/2022 16:41 Philippe Altherr <philippe.altherr@gmail.com> wrote:
> I don't think there is a problem. At least not a new problem because Zsh 5.8 and Zsh dev behave the same way.
> 
> Note that if you replace the body of "f" with just "false" you get the same results.

Yes, you're correct.  We should probably document this somehow.

pws

diff --git a/Doc/Zsh/options.yo b/Doc/Zsh/options.yo
index 445052617..dbaab08f4 100644
--- a/Doc/Zsh/options.yo
+++ b/Doc/Zsh/options.yo
@@ -1744,6 +1744,12 @@ Exiting due to tt(ERR_EXIT) has certain interactions with asynchronous
 jobs noted in
 ifzman(the section JOBS in zmanref(zshmisc))\
 ifnzman(noderef(Jobs & Signals)).
+
+It should also be noted that this option forces an immediate
+return to the command prompt when the non-zero status occurs
+in a sequence of commands typed on the command line.  In other
+words, the sequence of commands typed by the user may be
+thought of as a script for this purpose.
 )
 pindex(ERR_RETURN)
 pindex(NO_ERR_RETURN)
@@ -1772,6 +1778,9 @@ function, code inside it is considered separately: it may force a return
 from tt(summit) (assuming the option remains set within tt(summit)), but
 not from the enclosing context.  This behaviour is different from
 tt(ERR_EXIT) which is unaffected by function scope.
+
+Like tt(ERR_EXIT), this option forces an immediate return to the
+command prompt in interactive shells.
 )
 pindex(EVAL_LINENO)
 pindex(NO_EVAL_LINENO)


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

* Re: New problem with ERR_RETURN ?
  2022-12-07 16:41 ` Philippe Altherr
  2022-12-07 16:53   ` Peter Stephenson
@ 2022-12-07 16:58   ` Bart Schaefer
  1 sibling, 0 replies; 9+ messages in thread
From: Bart Schaefer @ 2022-12-07 16:58 UTC (permalink / raw)
  To: Philippe Altherr; +Cc: Zsh hackers list

On Wed, Dec 7, 2022 at 8:42 AM Philippe Altherr
<philippe.altherr@gmail.com> wrote:
>
> At least not a new problem because Zsh 5.8 and Zsh dev behave the same way.

I should have checked that.  Thanks.

> Note also that if you run "return; echo $?" nothing is printed.

That's "documented" in the code, though, as an explicit exception for
interactive mode.


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

* Re: New problem with ERR_RETURN ?
  2022-12-07 16:53   ` Peter Stephenson
@ 2022-12-07 17:02     ` Bart Schaefer
  2022-12-07 17:07       ` Peter Stephenson
  0 siblings, 1 reply; 9+ messages in thread
From: Bart Schaefer @ 2022-12-07 17:02 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: Zsh hackers list

On Wed, Dec 7, 2022 at 8:55 AM Peter Stephenson
<p.w.stephenson@ntlworld.com> wrote:
>
> +
> +It should also be noted that this option forces an immediate
> +return to the command prompt when the non-zero status occurs
> +in a sequence of commands typed on the command line.  In other
> +words, the sequence of commands typed by the user may be
> +thought of as a script for this purpose.

Um, no, it doesn't return to the prompt, it kills the shell.


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

* Re: New problem with ERR_RETURN ?
  2022-12-07 17:02     ` Bart Schaefer
@ 2022-12-07 17:07       ` Peter Stephenson
  2022-12-08  6:05         ` Lawrence Velázquez
  0 siblings, 1 reply; 9+ messages in thread
From: Peter Stephenson @ 2022-12-07 17:07 UTC (permalink / raw)
  To: Zsh hackers list

> On 07/12/2022 17:02 Bart Schaefer <schaefer@brasslantern.com> wrote:
> On Wed, Dec 7, 2022 at 8:55 AM Peter Stephenson
> <p.w.stephenson@ntlworld.com> wrote:
> >
> > +
> > +It should also be noted that this option forces an immediate
> > +return to the command prompt when the non-zero status occurs
> > +in a sequence of commands typed on the command line.  In other
> > +words, the sequence of commands typed by the user may be
> > +thought of as a script for this purpose.
> 
> Um, no, it doesn't return to the prompt, it kills the shell.

Yes, that would presumably require testing with a different
option, wouldn't it?

diff --git a/Doc/Zsh/options.yo b/Doc/Zsh/options.yo
index 445052617..b2213eb44 100644
--- a/Doc/Zsh/options.yo
+++ b/Doc/Zsh/options.yo
@@ -1744,6 +1744,9 @@ Exiting due to tt(ERR_EXIT) has certain interactions with asynchronous
 jobs noted in
 ifzman(the section JOBS in zmanref(zshmisc))\
 ifnzman(noderef(Jobs & Signals)).
+
+Note this behaviour is not disabled in interactive shells ---
+a non-zero status on the command line causes the shell to exit.
 )
 pindex(ERR_RETURN)
 pindex(NO_ERR_RETURN)
@@ -1772,6 +1775,12 @@ function, code inside it is considered separately: it may force a return
 from tt(summit) (assuming the option remains set within tt(summit)), but
 not from the enclosing context.  This behaviour is different from
 tt(ERR_EXIT) which is unaffected by function scope.
+
+It should also be noted that this option forces an immediate
+return to the command prompt when the non-zero status occurs
+in a sequence of commands typed on the command line.  In other
+words, the sequence of commands typed by the user may be
+thought of as a function for this purpose.
 )
 pindex(EVAL_LINENO)
 pindex(NO_EVAL_LINENO)


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

* Re: New problem with ERR_RETURN ?
  2022-12-07 17:07       ` Peter Stephenson
@ 2022-12-08  6:05         ` Lawrence Velázquez
  2022-12-08  9:24           ` Peter Stephenson
  0 siblings, 1 reply; 9+ messages in thread
From: Lawrence Velázquez @ 2022-12-08  6:05 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: zsh-workers

On Wed, Dec 7, 2022, at 12:07 PM, Peter Stephenson wrote:
> @@ -1772,6 +1775,12 @@ function, code inside it is considered 
> separately: it may force a return
>  from tt(summit) (assuming the option remains set within tt(summit)), 
> but
>  not from the enclosing context.  This behaviour is different from
>  tt(ERR_EXIT) which is unaffected by function scope.
> +
> +It should also be noted that this option forces an immediate
> +return to the command prompt when the non-zero status occurs
> +in a sequence of commands typed on the command line.  In other
> +words, the sequence of commands typed by the user may be
> +thought of as a function for this purpose.
>  )
>  pindex(EVAL_LINENO)
>  pindex(NO_EVAL_LINENO)

Bikeshedding perhaps, but this sentence already exists just above:

	This will trigger an exit at the outermost level of a
	non-interactive script.

Maybe any new text should come right after this?  That would keep
the explanations about how ERR_RETURN affects behavior at the top
level in one place.

-- 
vq


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

* Re: New problem with ERR_RETURN ?
  2022-12-08  6:05         ` Lawrence Velázquez
@ 2022-12-08  9:24           ` Peter Stephenson
  0 siblings, 0 replies; 9+ messages in thread
From: Peter Stephenson @ 2022-12-08  9:24 UTC (permalink / raw)
  To: zsh-workers

> On 08/12/2022 06:05 Lawrence Velázquez <larryv@zsh.org> wrote:
> Bikeshedding perhaps, but this sentence already exists just above:
> 
> 	This will trigger an exit at the outermost level of a
> 	non-interactive script.
> 
> Maybe any new text should come right after this?  That would keep
> the explanations about how ERR_RETURN affects behavior at the top
> level in one place.

That will make it more compact, too.

pws

diff --git a/Doc/Zsh/options.yo b/Doc/Zsh/options.yo
index 445052617..e92969531 100644
--- a/Doc/Zsh/options.yo
+++ b/Doc/Zsh/options.yo
@@ -1744,6 +1744,9 @@ Exiting due to tt(ERR_EXIT) has certain interactions with asynchronous
 jobs noted in
 ifzman(the section JOBS in zmanref(zshmisc))\
 ifnzman(noderef(Jobs & Signals)).
+
+Note this behaviour is not disabled in interactive shells ---
+a non-zero status on the command line causes the shell to exit.
 )
 pindex(ERR_RETURN)
 pindex(NO_ERR_RETURN)
@@ -1756,7 +1759,10 @@ If a command has a non-zero exit status, return immediately from the
 enclosing function.  The logic is similar to that for tt(ERR_EXIT),
 except that an implicit tt(return) statement is executed instead of an
 tt(exit).  This will trigger an exit at the outermost level of a
-non-interactive script.
+non-interactive script.  At the top level of an interactive shell,
+it will trigger a return to the command prompt; in other
+words, the sequence of commands typed by the user may be
+thought of as a function for this purpose.
 
 Normally this option inherits the behaviour of tt(ERR_EXIT) that
 code followed by `tt(&&)' `tt(||)' does not trigger a return.  Hence


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

end of thread, other threads:[~2022-12-08  9:24 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-07 16:17 New problem with ERR_RETURN ? Bart Schaefer
2022-12-07 16:37 ` Peter Stephenson
2022-12-07 16:41 ` Philippe Altherr
2022-12-07 16:53   ` Peter Stephenson
2022-12-07 17:02     ` Bart Schaefer
2022-12-07 17:07       ` Peter Stephenson
2022-12-08  6:05         ` Lawrence Velázquez
2022-12-08  9:24           ` Peter Stephenson
2022-12-07 16:58   ` Bart Schaefer

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