This might sound like a strange one, but I need to have all the errors that display in the CGI interface of my program to NOT have the script name or line numbers. For example, I'm using CGI::Carp to intercept any fatal errors:
use strict; use CGI::Carp qw/fatalsToBrowser set_message/; BEGIN { sub die_nice { # this will intercept any fatals my $err = shift; print "<html>\n<body>\n<h1>Custom CGI Error</h1>\n"; print "<pre>$err</pre>\n"; print "[script-specific error/dump info goes here]\n"; print "</body>\n</html>\n"; warningsToBrowser(1); } set_message(\&die_nice); } die('[this is the message passed to die]');
Now, running this code would (more or less) produce this in my browser:
[this is the message passed to die] at /home/evan/dietest.cgi line 18.
The thing is, once I put it into production, I'd only want the users to see [this is the message passed to die] while the full error would still appear in the apache error log. the only way I can think of doing this is to filter the error message like so:
sub die_nice { my $err = shift; $err =~ s/ at \S+ line \d+//g print "<html>\n<body>\n<h1>Custom CGI Error</h1>\n"; print "<pre>$err</pre>\n"; print "[script-specific error/dump info goes here]\n"; print "</body>\n</html>\n"; warningsToBrowser(1); }
This will work, mind you (im using it right now), but it seems like a hacky solution, plus what if the regex matches some other part of a strangely worded error...is there a Better Way™?

__________
Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
- Terry Pratchett


In reply to error messages without program names or line numbers by EvanK

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.