Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: [PATCH] More ERR_EXIT (was Re: Tests RE behavior of ERR_EXIT)



I think that I found the problem. Function calls do save and restore noerrexit. They should do the same for this_noerrexit. Furthermore exectry needs a "this_noerrexit = 1;" at the very end like all the other "exec" functions in loop.c. If I do these two changes and revert your two patches, then I think everything works (my tests and the Zsh tests). I will try to confirm that after some sleep.

 (
   setopt ERR_EXIT
   { { { false && true }
        } always { print INSIDE: $? } }
   print OUTSIDE
 )

The above should print "INSIDE: 1" (thus not exit) and then exit
without printing OUTSIDE.

No, I don't think so. "{ ... }" and "{ ... } always { ... }" are both compound commands that should never trigger an ERR_EXIT on a non-zero exit status produced by a "false && true" that is coming from the inside (i.e., that is bubbling up). If you replace the "{ ... } always { ... }" with an "if true; then { ... } else { ... }" then you can check with Bash that it prints "OUTSIDE" (but obviously not "INSIDE").

However, the following should trigger an ERR_EXIT when "foo" returns. With my changes, it does.

set -e
function foo() {
   { { { false && true } } always { print INSIDE: $? } }
}
foo
echo OUTSIDE

Interestingly, this example also works in Zsh 5.8. I guess it's thanks to the missing "this_noerrexit = 1;" in exectry. The version with an "if/then/else" instead of the "always" only works with my changes.

Philippe



Messages sorted by: Reverse Date, Date, Thread, Author