public inbox for [email protected]
help / color / mirror / Atom feedFrom: Justin Pryzby <[email protected]>
To: bt22nakamorit <[email protected]>
Cc: [email protected]
Subject: Re: Make ON_ERROR_STOP stop on shell script failure
Date: Wed, 2 Nov 2022 06:58:01 -0500
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>
On Fri, Sep 16, 2022 at 03:55:33PM +0900, bt22nakamorit wrote:
> Hi,
>
> """\set ON_ERROR_STOP on""" stops any subsequent incoming query that comes
> after an error of an SQL, but does not stop after a shell script ran by
> """\! <some command>""" returning values other than 0, -1, or 127, which
> suggests a failure in the result of the shell script.
Actually, I think this could be described as a wider problem (not just
ON_ERROR_STOP). The shell's exit status is being ignored (except for -1
and 127).
Shouldn't the user be able to do something with the exit status ?
Right now, it seems like they'd need to wrap the shellscript with
"if ! ...; then echo failed; fi"
and then \gset and compare with "failed"
I think it'd be a lot better to expose the script status to psql.
(without having to write "foo; echo status=$?").
Another consideration is that shellscripts can exit with a nonzero
status due to the most recent conditional (like: if || &&).
For example, consider shell command like:
"if foo; then bar; fi" or "foo && bar"
If foo has nonzero status, then bar isn't run.
If that's the entire shell script, the shell will *also* exit with foo's
nonzero status. (That's the reason why people write "exit 0" as the
last line of a shell script. It's easy to believe that it was going to
"exit 0" in any case; but, what it was actually going to do was to "exit
$?", and $? can be nonzero after conditionals, even in "set -e" mode).
So a psql script like this would start to report as a failure any time
"foo" was false, even if that's the normal/typical case.
--
Justin
view thread (20+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected], [email protected]
Subject: Re: Make ON_ERROR_STOP stop on shell script failure
In-Reply-To: <[email protected]>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox