oghran has asked for the wisdom of the Perl Monks concerning the following question:

I've come across this issue a few times in my Perl life time, but previously I've always been able to fix it after messing with the code for long enough. Right now however its not happening at all and I don't have alot of time to manually debug the whole script.

Anyway, my point is that I'm using CGI::Carp but yet I still am getting 500 Internal Server Error in the browser. Below is the brief snippit of code that includes the module:


###########  TO IMPLEMENT
# Build in formatting

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

#open new cgi
$q = new CGI;

Incase anyone suggests it the module does exist, and I've run the script successfully before but this time some of the parameters are causing it to fail.

Is there anything that causes CGI::Carp not to work and just return the usual 500 server error ? Is there any other way I can forceable return errors to the browser ?

Thanks for any help or suggestions.

Replies are listed 'Best First'.
Re: CGI::Carp failing to report errors
by Limbic~Region (Chancellor) on Oct 29, 2003 at 20:39 UTC
    oghran,
    First verify that you can do the following without a problem
    perl -MCGI::Carp perl -MCGI
    Then take a look at redirecting error messages from the docs. If you are on a system where you can't get at the web logs, you can use this method to write your own. I had to do this on a system where I didn't have permission to read the Apache logs.

    If you absolutely want to have the errors go to the web browser, you could probably modify the BEGIN block to print the proper header and use STDOUT instead of a regular file. I haven't tested that though.

    Hope this helps - L~R

Re: CGI::Carp failing to report errors
by Ovid (Cardinal) on Oct 29, 2003 at 20:42 UTC

    Without seeing the rest of the code, it's difficult to say. Also, seeing the actual error message might help. Have you looked in your error logs? A syntax error will cause your code to not compile, thus causing a 500 error and not allowing CGI::Carp to function. Also, a bad shebang line could be the problem. It's tough to narrow down without the actual error.

    Cheers,
    Ovid

    New address of my CGI Course.

      A syntax error [...] not allowing CGI::Carp to function.

      Although there was a recent version of CGI::Carp that failed to catch compile-time errors, it is supposed to catch those and it can catch compile-time errors that occur in code after the use CGI::Carp statement.

      So make the use CGI::Carp statement the first statement before you include any other modules. It still won't be able to catch errors in the #! line and certain configuration errors (or the lack of the CGI::Carp module itself or modules it depends upon), but I'll put even money on it finding this error.

                      - tye
Re: CGI::Carp failing to report errors
by talexb (Chancellor) on Oct 29, 2003 at 20:42 UTC
    • What does the error log say?
    • What was the last thing that you changed?
    • Does your CGI have execute permissions?
    --t. alex
    Life is short: get busy!
Re: CGI::Carp failing to report errors
by Hagbone (Monk) on Oct 30, 2003 at 01:39 UTC
    L~R mentions:

    "If you absolutely want to have the errors go to the web browser, you could probably modify the BEGIN block to print the proper header and use STDOUT instead of a regular file. I haven't tested that though."

    In the past (when I didn't have access to the error log file), I used the following to get errors to print to the browser. I can in no way claim credit for the snippet below, but humbly offer it in the spirit that what once helped me may help you.

    #Put the following code at the top of the script, just below #!/usr/bi +n/perl. #Run the program from your browser, and tell us what is printed there. BEGIN { local($|) = 1; # Temporarily turn off bufferi +ng print "Content-type: text/plain\n\n"; my $date = localtime; print "Script $0\nrunning on $date (Perl version $])\n\n"; unless (open STDERR, ">&STDOUT") { print "Can't redirect STDERR: $!"; exit; } print "\n"; }
    Hagbone
Re: CGI::Carp failing to report errors
by theAcolyte (Pilgrim) on Oct 30, 2003 at 10:51 UTC

    You may want to have a look at what version of the CGI::Carp module you are using. There is indeed a bug in a fairly recent version that caused fatalsToBrowser to fail.

    After I had verified that it was indeed the module and not my own incompetence (with the help of a monk here) I submitted the bug to Lincoln Stein who acknowledged it. I'm not sure if it was fixed in the latest release (3.0) but the last 2.xx release was a culprit.

    I downgraded one release at at time until I had a working version. I arrived at this when I installed CGI.pm 2.93 using CPAN.pm which includes CGI::Carp 1.20.

    To check your versions you can run this code quickly:

    #!/usr/bin/perl use CGI; use CGI::Carp; print "carp .. $CGI::Carp::VERSION\ncgi .. $CGI::VERSION\n\n";

    Good luck. :)