2

I am writing a perl web application running with apache and want to redirect error messages to the browser for debugging. For this, I found fatalsToBrowser from CGI::Carp.

Unfortunately, I still get an 'Internal Server Error' instead of the error message, which still ends up in the apache error log. Here is my code:

package Test;
use strict;
use warnings;
use CGI;
use CGI::Carp qw(fatalsToBrowser);
use Apache2::Request;

sub handler {
    my $request = Apache2::Request->new(shift);
    die("This is an error");
    print "here\n";
    return 1;
}

1;

In the documentation of CGI::Carp I read "Note that fatalsToBrowser may not work well with mod_perl version 2.0 and higher."

I am using mod_perl 2 and if I use fatalsToBrowser in a simple 'Hello World' cgi example, it works. But I am not sure if this function would not work in my setting or if I am doing something wrong.

Does anyone have an idea how to get this to work (maybe also with alternatives to CGI::Carp)?

szabgab
  • 6,202
  • 11
  • 50
  • 64
user1981275
  • 13,002
  • 8
  • 72
  • 101
  • Perhaps http://stackoverflow.com/questions/1174463/catching-errors-with-both-mod-cgi-mod-perl – mpapec Jul 03 '14 at 12:25
  • Does placing `local $SIG{__DIE__} = \&CGI::Carp::die;` in `handler` help? – ikegami Jul 03 '14 at 14:47
  • A possibility is that the exception handler overrides the custom message handler CGI::Carp sets up. – ikegami Jul 03 '14 at 14:54
  • Does `$ENV{MOD_PERL}` exists? – ikegami Jul 03 '14 at 14:55
  • @ikegami: `$ENV{MOD_PERL}` is mod_perl/2.0.5. When I place the `$SIG{__DIE__}` in Handler, but it still gives me an 'internal server error'. – user1981275 Jul 03 '14 at 15:49
  • If I overwrite `$SIG{__DIE__} = sub { print "

    Error

    ", $_[0]; exit();};`, I get the error message in the browser and my small example works, however, in my larger applications there can be exceptions, some are caught by `$SIG{__DIE__}` and some not...
    – user1981275 Jul 03 '14 at 15:54

0 Answers0