Re: warning handling in Perl scripts - Mailing list pgsql-hackers

From David E. Wheeler
Subject Re: warning handling in Perl scripts
Date
Msg-id 2EC02B9C-0E3E-41C8-8B89-A0F90A107129@justatheory.com
Whole thread Raw
In response to Re: warning handling in Perl scripts  (Alvaro Herrera <alvherre@commandprompt.com>)
Responses Re: warning handling in Perl scripts
List pgsql-hackers
On Jun 25, 2012, at 5:51 PM, Alvaro Herrera wrote:

>> However, that works only for the current lexical scope. If there are warnings in the code you are calling from the
currentscope, the use of `local $SIG{__WARN__}` is required. 
>
> So lets add 'FATAL' to the already existing "use warnings" lines in
> Catalog.pm and genbki.pl.
>
> I think the other files we should add this to  are generate-errcodes.pl,
> generate-plerrorcodes.pl, generate-spiexceptions.pl, Gen_fmgrtab.pl.
> Maybe psql/create_help.pl too.
>
> We have a bunch of files in ECPG and MSVC areas and others in src/tools;
> not sure about those.
>
> We also have gen_qsort_tuple.pl which amusingly does not even
> use warnings.

Hrm, I think that `use warnings 'FATAL';` might only work for core warnings. Which is annoying. I missed what was
warningup-thread, but the most foolproof way to make all warnings fatal is the originally suggested 
 local $SIG{__WARN__} = sub { die shift };

A *bit* cleaner is to use Carp::croak:
   use Carp;   local $SIG{__WARN__} = \&croak;

Or if you wanted to get a stack trace out of it, use Carp::confess:
   use Carp;   local $SIG{__WARN__} = \&confess;

Exception-handling in Perl is one of the few places that annoy me regularly.

Best,

David



pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: [PATCH 04/16] Add embedded list interface (header only)
Next
From: Robert Haas
Date:
Subject: Re: pg_upgrade broken by xlog numbering