While in 'tinker' mode, I usually use CGI::Carp to send fatals to the browser. But I ran into an issue today where something I was doing in my main program was causing an error to spew out of CGI::Session. It took me a little longer than it should have to figure out what was going on, but it turned out that since the error was spitting out of the module instead of the main code, it wasn't trapped by CGI::Carp.

Of course looking in the server log gave the necessary clues. But since I was expecting to see errors show up in the browser while in development, I didn't immediately think to check the server's error log.

The easiest solution is to remember to check there when I observe what seems to be silent failure. But I'm wondering if there's a solution that would enable CGI::Session to fall under the CGI::Carp umbrella instead.

My current script sets up the carp handlers in a BEGIN block, as follows:

use CGI::Carp qw(fatalsToBrowser set_message); BEGIN { sub handle_errors { my $msg = shift; print "<h2>Error trapped by CGI::Carp</h2>\n"; $msg = s/\n/<br />/g; print "<p>Message: $msg</p>\n<pre>\n"; foreach my $key ( keys %ENV ) { print " $key\t $ENV{$key}\n"; } print "</pre>\n"; } set_message(\&handle_errors); } use Modern::Perl; use CGI::Simple; use CGI::Session; # and so on...

Dave


In reply to Sending warnings from CGI::Session to browser by davido

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.