skyknight has asked for the wisdom of the Perl Monks concerning the following question:

I have a command line script that I wrote that includes a whole pile of other Perl libraries that were written in house, many of which are old, krufty, etc. While this is in fact a command line script, our primary environment is the web, and so I am suspicious that my problem is the result of people making assumptions about where the code would be called. So, my problem... My script does a healthy amount of error checking and dies with appropriate error messages. What I would expect to see is something of the form...

ERROR: User is a moron. Please step away from the keyboard. at /path/ +to/offending/file line 42

but instead I get something of the form...

[Wed Aug 6 11:48:17 2003] scriptname: ERROR: User is a moron. Please + step away from the keyboard. at /path/to/offending/file at line 42

I don't want this behavior because it makes things really cluttered. Even more annoying is if you trap and propagate errors then it sticks this extra junk on at each level making a huge mess of things. I added the following line of code both to the offending script which includes boatloads of libraries, as well as to some other script that does not include any such libraries and simply dies for the heck of it...

print "keys: " . join(',', keys(%SIG)), "\n";

This yielded a whole bunch of handlers in the bare bones script...

keys: ABRT,ALRM,BUS,CANCEL,CHLD,CLD,CONT,EMT,FPE,FREEZE,HUP,ILL,INT,IO +,IOT,KILL,LOST,LWP,NUM39,NUM40,NUM41,NUM42,NUM43,NUM44,PIPE,POLL,PROF +,PWR,QUIT,RTMAX,RTMIN,SEGV,STOP,SYS,TERM,THAW,TRAP,TSTP,TTIN,TTOU,URG +,USR1,USR2,VTALRM,WAITING,WINCH,XCPU,XFSZ,__WARN__

The other, real script gave the following...

keys: ABRT,ALRM,BUS,CANCEL,CHLD,CLD,CONT,EMT,FPE,FREEZE,HUP,ILL,INT,IO +,IOT,KILL,LOST,LWP,NUM39,NUM40,NUM41,NUM42,NUM43,NUM44,PIPE,POLL,PROF +,PWR,QUIT,RTMAX,RTMIN,SEGV,STOP,SYS,TERM,THAW,TRAP,TSTP,TTIN,TTOU,URG +,USR1,USR2,VTALRM,WAITING,WINCH,XCPU,XFSZ,__DIE__,__WARN__

It would seem that the difference between the two is the __DIE__ handler that some library, somewhere has gone and installed unbeknowst to me. I verified this by adding the following line to my script...

undef $SIG{__DIE__};

This got my code to die with an appropriately formatted message, but it seems a little krufty to do that, and I'd really like to know from whence the coderef that is in $SIG{__DIE__} has sprung. I could probably accomplish this, with some effort, by using some code introspection libraries. I am wondering though, is this a common effect of some well known library or other? I perldoc'd Carp and didn't get any leads from there.

Replies are listed 'Best First'.
Re: UADH: Unidentified Annoying Die Handler
by Aristotle (Chancellor) on Aug 06, 2003 at 16:58 UTC
    [Wed Aug 6 11:48:17 2003] scriptname: ERROR: User is a moron. Please + step away from the keyboard. at /path/to/offending/file at line 42
    Looks like CGI::Carp to me.

    Makeshifts last the longest.

      Yeah... I just did a grep for CGI::Carp in lib/perl and it is in fact used. I imagine that is the root cause of these funny error message formats. Thanks a lot.
Re: UADH: Unidentified Annoying Die Handler
by dws (Chancellor) on Aug 06, 2003 at 16:17 UTC
    I'd really like to know from whence the coderef that is in $SIG{__DIE__} has sprung.

    I may be missing something, but have you grepped through the other source for __DIE__?

      Sorry, I guess I did leave that as a doubt. All of the libraries developed in-house are in lib/perl and I ran

      find lib/perl -exec grep __DIE__ {} \; -print

      getting back absolutely no results. It was thus that I came to the conclusion that the __DIE__ handler is coming as a secondary effect of including an in-house library that must include some third party library that installs a custom __DIE__ handler.

        Just a hint - it's gonna be a bit quicker to grep -r __DIE__ lib/perl ...

        Makeshifts last the longest.