Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ogiXI-0008HX-Ip for pgsql-hackers@arkaria.postgresql.org; Fri, 07 Oct 2022 08:16:48 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1ogiXH-0002oA-0x for pgsql-hackers@arkaria.postgresql.org; Fri, 07 Oct 2022 08:16:47 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ogiXG-0002o1-Nm for pgsql-hackers@lists.postgresql.org; Fri, 07 Oct 2022 08:16:46 +0000 Received: from oss.nttdata.com ([49.212.34.109]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ogiXF-0005Hb-6k for pgsql-hackers@lists.postgresql.org; Fri, 07 Oct 2022 08:16:46 +0000 Received: from [10.6.216.34] (unknown [203.180.48.65]) by oss.nttdata.com (Postfix) with ESMTPSA id 69EAA60427; Fri, 7 Oct 2022 17:16:41 +0900 (JST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.7 at oss.nttdata.com Message-ID: <3f489f1f-3f91-8a98-4cf3-bad7ff037dc2@oss.nttdata.com> Date: Fri, 7 Oct 2022 17:16:40 +0900 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.13.1 Subject: Re: Make ON_ERROR_STOP stop on shell script failure Content-Language: en-US To: bt22nakamorit Cc: Kyotaro Horiguchi , pgsql-hackers@lists.postgresql.org References: <20220916.173035.322733707258561235.horikyota.ntt@gmail.com> <4c61d434cb72b2237b3279797b2a387f@oss.nttdata.com> <8a022f2c8de93ea79116f0b7eb42248a@oss.nttdata.com> From: Fujii Masao In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2022/09/30 16:54, bt22nakamorit wrote: > 2022-09-21 11:45 に Fujii Masao wrote: >> We can execute the shell commands via psql in various ways >> other than \! meta-command. For example, >> >> * `command` >> * \g | command >> * \gx | command >> * \o | command >> * \w | command >> * \copy ... program 'command' >> >> ON_ERROR_STOP should handle not only \! but also all the above in the same way? >> >> >> One concern about this patch is that some applications already depend on >> the current behavior of ON_ERROR_STOP, i.e., psql doesn't stop even when >> the shell command returns non-zero exit code. If so, we might need to >> extend ON_ERROR_STOP so that it accepts the following setting values. >> >> * off - don't stop even when either sql or shell fails (same as the >> current behavior) >> * on or sql - stop only whensql fails (same as the current behavior) >> * shell - stop only when shell fails >> * all - stop when either sql or shell fails >> >> Thought? >> >> Regards, > > I agree that some applications may depend on the behavior of previous ON_ERROR_STOP. > I created a patch that implements off, on, shell, and all option for ON_ERROR_STOP. > I also edited the code for \g, \o, \w, and \set in addition to \! to return exit status of shell commands for ON_ERROR_STOP. > > There were discussions regarding the error messages for when shell command fails. > I have found that \copy already handles exit status of shell commands when it executes one, so I copied the messages from there. > More specifically, I referred to """bool do_copy(const char *args)""" in src/bin/psql/copy.c > > Any feedback would be very much appreciated. Thanks for updating the patch! The patch failed to be applied into the master cleanly. Could you rebase it? patching file src/bin/psql/common.c Hunk #1 succeeded at 94 (offset 4 lines). Hunk #2 succeeded at 104 (offset 4 lines). Hunk #3 succeeded at 133 (offset 4 lines). Hunk #4 succeeded at 1869 with fuzz 1 (offset 1162 lines). Hunk #5 FAILED at 2624. 1 out of 5 hunks FAILED -- saving rejects to file src/bin/psql/common.c.rej Regards, -- Fujii Masao Advanced Computing Technology Center Research and Development Headquarters NTT DATA CORPORATION