views:

190

answers:

1

LS,

I'm using the following code to test the outputting of fatal errors to the browser:

use CGI;
use CGI::Carp qw(fatalsToBrowser);

die "test";

I am expecting to see some error in the browser, but there isn't any, I just get a regular 500 response. I forgot that I had custom error pages on for remote requests, and I now get Script failed to send data..

Also:

> perl -w index.pl
Status: 500
Content-type: text/html

<h1>Software error:</h1>
<pre>test at index.pl line 4.</pre>
<p>
For help, please send mail to this site's webmaster, giving this error message and the time and date of the error.

</p>
[Mon Feb  8 18:29:52 2010] index.pl: test at index.pl line 4.

Kind regards,

Matthias Vance

+2  A: 

Try printing a couple of new lines before anything. That signals the end of HTTP headers to the server as the 'CGI standard' says. Or you may be able to use something like this: (as copied from the Carp man page):

use CGI::Carp qw(set_die_handler);
BEGIN {
   sub handle_errors {
      my $msg = shift;
      print "content-type: text/html\n\n";
      print "<h1>Oh gosh</h1>";
      print "<p>Got an error: $msg</p>";
  }
  set_die_handler(\&handle_errors);
}

If that doesn't work here are a few more tricks:

#!perl
BEGIN { $| = 1; print "\n\n" }
open STDERR, ">&STDOUT";

..And a few more tricks in this Perl Journal article.

Maxwell Troy Milton King
This still just returns a 500.
Matthias Vance
What about putting this at the top of your cgi file: BEGIN { $| = 1; print "\n\n" }
Maxwell Troy Milton King
That gives me a 200, but it doesn't print the `die`.
Matthias Vance
.. and add a stderr redirect. see above.
Maxwell Troy Milton King
I think I'm going to use this workaround. Works perfect so far!
Matthias Vance