EvanK has asked for the wisdom of the Perl Monks concerning the following question:
Now, running this code would (more or less) produce this in my browser: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]');
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:[this is the message passed to die] at /home/evan/dietest.cgi line 18.
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™?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); }
__________
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: error messages without program names or line numbers
by BrowserUk (Patriarch) on Aug 04, 2006 at 15:50 UTC | |
by Sidhekin (Priest) on Aug 04, 2006 at 15:54 UTC | |
by EvanK (Chaplain) on Aug 04, 2006 at 16:30 UTC | |
by jhourcle (Prior) on Aug 04, 2006 at 17:21 UTC | |
by cdarke (Prior) on Aug 04, 2006 at 20:08 UTC | |
|
Re: error messages without program names or line numbers
by perladdict (Chaplain) on Aug 04, 2006 at 20:31 UTC | |
by liverpole (Monsignor) on Oct 14, 2006 at 14:09 UTC |