Re: pgindent exit status if a file encounters an error

From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Ashutosh Bapat <ashutosh(dot)bapat(dot)oss(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Andrew Dunstan <andrew(at)dunslane(dot)net>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: pgindent exit status if a file encounters an error
Date: 2024-10-16 23:26:10
Message-ID: ZxBLkouN0oSx12pC@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


Uh, where are we on this?

---------------------------------------------------------------------------

On Fri, Jun 28, 2024 at 06:05:35PM +0530, Ashutosh Bapat wrote:
>
>
> On Wed, Jun 26, 2024 at 8:54 PM Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>
> Ashutosh Bapat <ashutosh(dot)bapat(dot)oss(at)gmail(dot)com> writes:
> > The usage help mentions exit code 2 specifically while describing --check
> > option but it doesn't mention exit code 1. Neither does the README. So I
> > don't think we need to document exit code 3 anywhere. Please let me know
> if
> > you think otherwise.
>
> I think we should have at least a code comment summarizing the
> possible exit codes, along the lines of
>
> # Exit codes:
> #   0 -- all OK
> #   1 -- could not invoke pgindent, nothing done
> #   2 -- --check mode and at least one file requires changes
> #   3 -- pgindent failed on at least one file
>
>
> Thanks. Here's a patch with these lines.
>  
> In an offline chat Andrew mentioned that he expects more changes in the patch
> and he would take care of those. Will review and test his patch.
>
> --
> Best Wishes,
> Ashutosh Bapat

> From 2a61830f0a2b6559d04bef75c6aa224e30ed1609 Mon Sep 17 00:00:00 2001
> From: Ashutosh Bapat <ashutosh(dot)bapat(at)enterprisedb(dot)com>
> Date: Wed, 26 Jun 2024 15:46:53 +0530
> Subject: [PATCH 1/2] pgindent exit status on error
>
> When pg_bsd_indent exits with a non-zero status or reports an error,
> make pgindent exit with non-zero status 3. The program does not exit on
> the first instance of the error. Instead it continues to process
> remaining files as long as some other exit condition is encountered, in
> which case exit code 3 is reported.
>
> This helps to detect errors automatically when pgindent is run in shells
> which interpret non-zero exit status as failure.
>
> Author: Ashutosh Bapat
> Reviewed by: Andrew Dunstan
> Discussion: https://www.postgresql.org/message-id/CAExHW5sPRSiFeLdP-u1Fa5ba7YS2f0gvLjmKOobopKadJwQ_GQ@mail.gmail.com
> ---
> src/tools/pgindent/pgindent | 10 +++++++++-
> 1 file changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/src/tools/pgindent/pgindent b/src/tools/pgindent/pgindent
> index 48d83bc434..03b319c9c3 100755
> --- a/src/tools/pgindent/pgindent
> +++ b/src/tools/pgindent/pgindent
> @@ -1,5 +1,12 @@
> #!/usr/bin/perl
>
> +# Program to maintain uniform layout style in our C and Perl code.
> +# Exit codes:
> +# 0 -- all OK
> +# 1 -- could not invoke pgindent, nothing done
> +# 2 -- --check mode and at least one file requires changes
> +# 3 -- pgindent failed on at least one file
> +
> # Copyright (c) 2021-2024, PostgreSQL Global Development Group
>
> use strict;
> @@ -409,6 +416,7 @@ foreach my $source_filename (@files)
> if ($source eq "")
> {
> print STDERR "Failure in $source_filename: " . $error_message . "\n";
> + $status = 3;
> next;
> }
>
> @@ -429,7 +437,7 @@ foreach my $source_filename (@files)
>
> if ($check)
> {
> - $status = 2;
> + $status ||= 2;
> last unless $diff;
> }
> }
> --
> 2.34.1
>

--
Bruce Momjian <bruce(at)momjian(dot)us> https://momjian.us
EDB https://enterprisedb.com

When a patient asks the doctor, "Am I going to die?", he means
"Am I going to die soon?"

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Matthias van de Meent 2024-10-16 23:32:44 Re: Limiting overshoot in nbtree's parallel SAOP index scans
Previous Message Corey Huinker 2024-10-16 23:20:19 Re: Statistics Import and Export