Re: warning handling in Perl scripts

From: "David E(dot) Wheeler" <david(at)justatheory(dot)com>
To: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Robert Haas <robertmhaas(at)gmail(dot)com>, Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: warning handling in Perl scripts
Date: 2012-06-25 15:58:40
Message-ID: 2EC02B9C-0E3E-41C8-8B89-A0F90A107129@justatheory.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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 current scope, 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 warning up-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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Robert Haas 2012-06-25 16:06:25 Re: pg_upgrade broken by xlog numbering
Previous Message Tom Lane 2012-06-25 15:57:51 Re: [PATCH 04/16] Add embedded list interface (header only)