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

I have been using use CGI::Carp qw(fatalsToBrowser); and love it for debugging. Is there an equivalent that would send the errors as an email? Some times I get an email saying someome got an "Error" on a cgi program and they don't give any more information than that. It would be great if all cgi errors could be sent to me as an email. thanks bear_phillips

Replies are listed 'Best First'.
Re: Is there a CGI::Carp fatalstoEmail ?
by rob_au (Abbot) on Sep 26, 2002 at 14:38 UTC
    There isn't a standard 'fatalsToEmail' pragma for the CGI::Carp module, however it would not be particularly difficult to build such functionality using the set_message method. This method allows a subroutine to be specified which is called with the text of the error message that caused the script to die - For example:

    use CGI::Carp qw/ fatalsToBrowser set_message /; use Mail::Mailer; BEGIN { sub fatalsToEmail { my $error = shift; my $smtp = Mail::Mailer->new('smtp', Server => '127.0.0.1'); $smtp->open({ 'To' => 'you@yourdomain.com', 'From' => 'you@yourdomain.com' }); print $smtp $error; $smtp->close; } set_message(\&fatalsToEmail); }

    As outlined in the CGI::Carp man page, the set_message routine should be called from within a BEGIN in order to correctly interpret compile-time errors.

     

Re: Is there a CGI::Carp fatalstoEmail ?
by Mr. Muskrat (Canon) on Sep 26, 2002 at 14:36 UTC

      I just tried to visit merlyn's site to read the article, and discovered that WebSense is blocking access to the site. Why, you ask? "Keyword found: stone". Watch out, everyone, Randal's site is apparently drug-related! :-)

      (On the other hand, it did classify it as "Entertainment". :-) They got that much right.)

      Wally Hartshorn

Re: Is there a CGI::Carp fatalstoEmail ?
by gryphon (Abbot) on Sep 27, 2002 at 05:00 UTC

    Greetings bear,

    In addition to the wonderful responses you've already received, I'd add that it would be a good idea to have a fatalsToEmail and fatalsToBrowser routine. In a recent project I've been playing around with, I used the set_message with CGI::Carp fatalsToBrowser to send myself an email and display a "nice" error page to the user. Of course, the "nice" error page tells the user very little other than an apology and some contact information. For a future version, I was thinking about providing the user some sort of automated "summary" information about the particular error. Any such information should be vague enough as to not provide any crackers with any useful information.

    Oh, and as I'm sure someone has noted before, always make sure you turn off the "report full text of the error message to browser" feature before you launch go into public enviornment.

    gryphon
    code('Perl') || die;