zsh-users
 help / color / mirror / code / Atom feed
* abort if any error
@ 2021-08-06 18:42 Ray Andrews
  2021-08-06 21:07 ` Bart Schaefer
  0 siblings, 1 reply; 2+ messages in thread
From: Ray Andrews @ 2021-08-06 18:42 UTC (permalink / raw)
  To: Zsh Users

$ . wonderful_function; wonderful_function

[scrolls off the page ]

But, ooops, my last tweak to the function busted something so it wasn't 
sourced and what ran was the previous version.  Is there some way of 
forcing any script or command line or anything at all to stop 
unconditionally in case of an error on sourcing?  I can't think of a 
situation where I'd not want to stop and fix it.  If it were possible 
I'd bolt that on right at configuration.  I'm betting it can be done.




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

* Re: abort if any error
  2021-08-06 18:42 abort if any error Ray Andrews
@ 2021-08-06 21:07 ` Bart Schaefer
  0 siblings, 0 replies; 2+ messages in thread
From: Bart Schaefer @ 2021-08-06 21:07 UTC (permalink / raw)
  To: Ray Andrews; +Cc: Zsh Users

On Fri, Aug 6, 2021 at 11:42 AM Ray Andrews <rayandrews@eastlink.ca> wrote:
>
> $ . wonderful_function; wonderful_function
>
> But, ooops, my last tweak to the function busted something so it wasn't
> sourced and what ran was the previous version.  Is there some way of
> forcing any script or command line or anything at all to stop
> unconditionally in case of an error on sourcing?

The "." command should have returned an error (nozero) status if it
couldn't load the file, so the problem is that you used ";" between
the two commands.  That effectively ignores the exit status of the
first command and runs the second one regardless.  If you had used
"&&" instead, you would have gotten what you wanted.  There's nothing
you can put INSIDE a script file that will cause the sourcing shell to
interrupt a ";"-separated sequence of commands when the script has a
syntax error or other parse-time failure.

If your two sample commands had appeared in another script, instead of
at an interactive prompt, "setopt errexit" in that outer script would
have caused it to stop when the first command failed, but that should
be used carefully because it will cause the script to exit when ANY
command outside of a conditional test context returns a nonzero
status.

You DO NOT want to put "setopt errexit" in a script you will be
loading directly with the "." (or "source") commands, because that can
cause the whole interactive shell to exit.  Using errexit in a
function definition nested in a script file is OK, but as noted above
won't do any good if the function has a syntax error.


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

end of thread, other threads:[~2021-08-06 21:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-06 18:42 abort if any error Ray Andrews
2021-08-06 21:07 ` 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).