Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

use CGI::Carp qw(fatalsToBrowser);

by Heidegger (Hermit)
on Apr 09, 2003 at 11:19 UTC ( #249196=perlquestion: print w/replies, xml ) Need Help??

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

Dear Monks,

I'm debugging a perl web application on Apache. I want the errors to go to the browser instead of the Apache error.log file. I have included the directive use CGI::Carp qw(fatalsToBrowser); in my script. Unfortunately, the error don't appear in the browser - they still go to the error.log file.

Maybe I'm mistaken, such errors like: [Wed Apr 09 05:12:31 2003] [error] [client] syntax error at C:/Perl/site/lib/Mokslas/Manage/ line 232, near ") aren't supposed to go there?

Or maybe I have to include CGI::Carp module in another order? I have inherited my application from CGI::Application. Maybe it doesn't let me override fatalsToBrowser constant?

Thank you very much.

Replies are listed 'Best First'.
Re: use CGI::Carp qw(fatalsToBrowser);
by particle (Vicar) on Apr 09, 2003 at 11:33 UTC

    add use CGI::Carp qw/fatalsToBrowser/; as soon as possible, so it catches every error. since you're using CGI::Application, you should load it in the .pl file that calls your CGI::App-based module.

    ~Particle *accelerates*

Re: use CGI::Carp qw(fatalsToBrowser);
by Trimbach (Curate) on Apr 09, 2003 at 13:39 UTC
    If your CGI has a syntax error (and that's what it looks like from the error log) then that means your program has a compile-time error. CGI::Carp only catches run-time errors that occur after the use CGI::Carp code has been compiled; syntax errors occur before that and will still be reported to the Apache error log.

    If you have telnet access to your webserver type "perl -c" to check for compilation errors. Once that's ok you can finish your debugging from a web browser.

    Gary Blackburn
    Trained Killer

    Edited: Thanks tye for the clarification. :-)

      No, use is a compile-time directive and so even compile-time errors will be caught. But errors from lines of code that get compiled before the use CGI::Carp line of code gets compiled cannot be caught.

                      - tye
        Well, that's interesting. You're absolutely correct, but it seems odd to me that anything would get compiled before the use CGI::Carp is compiled, except maybe other use declarations or the contents of BEGIN blocks, since use is automatically placed in an implicit BEGIN block.

        A little experimentation reveals that perl throws syntax errors even before compilation really begins (or, at least before BEGIN blocks. This is implied in the Camel, where it says that "the Perl compiler reads through your entire program source before execution start." I guess when they say that BEGIN blocks execute as soon as possible they mean AFTER a syntax check, 'cause before that, it isn't possible. :-)

        I guess this makes sense... if perl can't parse the program it has to give up without executing anything... but it does make catching syntax errors in a CGI environment (no error-log, FTP only) problematic. I guess the alternative is to install Perl on your local machine and do all your syntax checks locally.

        Gary Blackburn
        Trained Killer

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://249196]
Approved by Tomte
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (2)
As of 2023-06-05 04:38 GMT
Find Nodes?
    Voting Booth?
    How often do you go to conferences?

    Results (22 votes). Check out past polls.