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

I have Perl installed on a Linux machine and am running scripts nicely. The only problem is that when I have an error in one of my scripts, instead of a helpful error message in my browser, I get the standard...
<b>Internal Server Error</b> The server encountered an internal error or misconfiguration and was u +nable to complete your request.
Does anyone know how I get my error messages working.
THanks

Replies are listed 'Best First'.
Re: I want errors
by davorg (Chancellor) on Jul 18, 2001 at 14:02 UTC

    As other have pointed out, your errors are going to your error log. This is, of course, the right place for them.

    If you want the Perl error messages to go to the browser then you can add the line:

    use CGI::Carp qw(fatalsToBrowser);

    to your script. Be warned however that this is probably not a good idea as explicit error messages can give crackers clues to security holes in your site. By all means send the errors to the browser during development, but you should go back to the "vanilla" error messages when the script goes live.

    --
    <http://www.dave.org.uk>

    Perl Training in the UK <http://www.iterative-software.com>

Re: I want errors
by nysus (Parson) on Jul 18, 2001 at 13:48 UTC
    You can do a couple of things. First, you can go to your log files. This is where the STDERR output gets directed when working with CGI. So all the error messages can be seen there. What you can also do is redirect the error messages to appear in your browser. Check out the cgi::carp module. Come back if you have other questions.

    $PM = "Perl Monk's";
    $MCF = "Most Clueless Friar Abbot Bishop";
    $nysus = $PM . $MCF;
    Click here if you love Perl Monks

Re: I want errors
by tachyon (Chancellor) on Jul 18, 2001 at 15:49 UTC

    To guarantee that your errors will appear in the browser add this BEGIN block just below the shebang line.

    BEGIN { $|=1; print "Content-type: text/html\n\n"; use CGI::Carp('fatalsToBrowser'); }

    This code does several things. Because it is in a begin block it executes before the rest of the script compiles so no matter how bad the error this will run. The $| switches off buffering, then we print a valid header, finally we enable CGI::Carp. Do not leave this block in production code as it is a security hazard.

    For full details on CGI problems and their solutions see this tutorial I wrote CGI Help Guide. It covers this topic and a number of other bits and bobs.

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Re: I want errors
by mattr (Curate) on Jul 18, 2001 at 13:55 UTC
    Most likely you are having something fail and try to print an error message to the browser (if you are accessing the program through a web browser) before you print the http header which should come first.

    Some things to check: check the file's permissions (755 or rwxr-xr-x), syntax (perl -c myfilename.cgi), perl location (which perl), and add a CGI header print statement at the top of it right after your shebang line (print "Content-type: text/html\n\n";). These examples are for Unix.

Re: I want errors!!
by shotgunefx (Parson) on Jul 18, 2001 at 15:19 UTC
    Look in your server logs or use CGI::Carp qw(fatalsToBrowsers)

    Depending on what you are doing, you may not want detailed error messages going to the browser (users) as they can expose internal stuff.

    -Lee

    "To be civilized is to deny one's nature."
Re: I want errors
by scottstef (Curate) on Jul 18, 2001 at 18:21 UTC
    you can also run a tail -f errors_file on your error log.

    "The social dynamics of the net are a direct consequence of the fact that nobody has yet developed a Remote Strangulation Protocol." -- Larry Wall

Re: I want errors
by nlafferty (Scribe) on Jul 18, 2001 at 19:25 UTC
    View the error_log in your /home/httpd/logs/ directory. That will give you some nice stuff. Also try running the scripts in your shell like:

    ./whatever.pl

    That should help emensly.