public inbox for [email protected]
help / color / mirror / Atom feedFrom: bt22nakamorit <[email protected]>
To: Kyotaro Horiguchi <[email protected]>
Cc: [email protected]
Subject: Re: Make ON_ERROR_STOP stop on shell script failure
Date: Tue, 20 Sep 2022 15:15:39 +0900
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>
<[email protected]>
<[email protected]>
2022-09-17 09:44 に bt22nakamorit さんは書きました:
> 2022-09-16 17:30 に Kyotaro Horiguchi さんは書きました:
>> At Fri, 16 Sep 2022 15:55:33 +0900, bt22nakamorit
>> <[email protected]> wrote in
>>> 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.
>>>
>>> For example, suppose that below is an SQL file.
>>> \set ON_ERROR_STOP on
>>> SELECT 1;
>>> \! false
>>> SELECT 2;
>>>
>>> The current design allows SELECT 2 even though the shell script
>>> returns a value indicating a failure.
>>
>> Since the "false" command did not "error out"?
>>
>>> I thought that this action is rather unexpected since, based on the
>>> word """ON_ERROR_STOP""", ones may expect that failures of shell
>>> scripts should halt the incoming instructions as well.
>>> One clear solution is to let failures of shell script stop incoming
>>> queries just like how errors of SQLs do currently. Thoughts?
>>
>> I'm not sure we want to regard any exit status from a succssful run as
>> a failure.
>>
>> On the other hand, the proposed behavior seems useful to me.
>>
>> So +1 from me to the proposal, assuming the corresponding edit of the
>> documentation happens.
>>
>> regards.
>
>> Since the "false" command did not "error out"?
> "false" command returns 1 which is an exit status code that indicates
> failure, but not error.
> I think it does not "error out" if that is what you mean.
>
>> So +1 from me to the proposal, assuming the corresponding edit of the
>> documentation happens.
> I will work on editing the document and share further updates.
>
> Thank you!
> Tatsu
I edited the documentation for ON_ERROR_STOP.
Any other suggestions?
Tatsu
Attachments:
[text/x-diff] stop_error.patch (1.2K, ../[email protected]/2-stop_error.patch)
download | inline diff:
diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml
index 9494f28063..2395678938 100644
--- a/doc/src/sgml/ref/psql-ref.sgml
+++ b/doc/src/sgml/ref/psql-ref.sgml
@@ -4143,7 +4143,9 @@ bar
<para>
By default, command processing continues after an error. When this
variable is set to <literal>on</literal>, processing will instead stop
- immediately. In interactive mode,
+ immediately. A nonzero exit status of a shell command, which indicates
+ failure, is also interpreted as an error that stops the processing.
+ In interactive mode,
<application>psql</application> will return to the command prompt;
otherwise, <application>psql</application> will exit, returning
error code 3 to distinguish this case from fatal error
diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c
index a141146e70..7445ca04ff 100644
--- a/src/bin/psql/command.c
+++ b/src/bin/psql/command.c
@@ -4989,6 +4989,10 @@ do_shell(const char *command)
pg_log_error("\\!: failed");
return false;
}
+ else if (result != 0) {
+ pg_log_error("command failed");
+ return false;
+ }
return true;
}
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