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

"I feel like I'm taking mad pills here". Until 48 hours ago, my scripts with CGI::Carp qw(fatalsToBrowser); all gave me useful information when they broke. Now all I get is Execution of foo.pl aborted due to compilation errors. The full info still appears in my error log. I didn't change anything! And to test it, I wrote:
#!/usr/bin/perl -w use strict; use CGI qw(:standard); use CGI::Carp qw(fatalsToBrowser); print header, h1('hello'); #$test = 1;
Which returns

Hello

... and then when I remove the comment, instead of getting
[Wed Dec 12 13:02:40 2001] carptest.pl: Execution of carptest.pl abort +ed due to compilation errors. [Wed Dec 12 13:02:40 2001] carptest.pl: Global symbol "$test" requires + explicit package name at carptest.pl line 9.
I get... yes, you guessed,
Execution of foo.pl aborted due to compilation errors
Well hell, you don't say? I think I could have worked that out...

Has anybody got any idea where I might start looking for the solution?

§ George Sherston

Replies are listed 'Best First'.
(jeffa) Re: CGI::Carp won't send fatalsToBrowser
by jeffa (Bishop) on Dec 12, 2001 at 20:27 UTC
    The one thing i really learned from my compiler class in college was that one should always be thankful of any error message one receives from the compiler (interpreter). Sometimes you just can't get an exact error message. Sometimes you just have to remind yourself that an error message is just a clue, and you have to play detective.

    How about this error: my $test = 1 / 0;. CGI::Carp tells us:

    Illegal division by zero at ... line 9.
    How about this error:
    my $array = 1; foreach (%$array) { print } #error: Can't use string ("1") as a HASH ref while "strict refs" in use at ... + line 11.
    Notice how in both of those errors, we were never informed of which variables were the culprits? That's because revealing such info to the user is a security hazard.

    However, why it won't tell us the line that the error occured on for an undeclared variable, I don't know. I would think that since the other two examples informed us of which line to look at, your error should to. My guess as to why is because the name of the variable is included in the error message that tells the line number.

    The solution - always use the error log. And if you can't access the error log - comment out 'use CGI::Carp' and run perl -c on your cgi script. Note that this won't inform us of the 'HASH ref while "strict refs"' error from my second example - to catch run-time errors, run your cgi script on the command line. TIMTOWTDI!

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    F--F--F--F--F--F--F--F--
    (the triplet paradiddle)
    
Re: CGI::Carp won't send fatalsToBrowser
by Rhandom (Curate) on Dec 12, 2001 at 20:45 UTC
    I've banged my head against the wall much before under the same problem. I believe the problem lies in that CGI::Carp is only able to catch $SIG{__DIE__} which can't even be set up until the code compiles.

    This doesn't answer why it happens, but we use it in our development all the time. Just simply run your cgi from the commandline. You will get a full listing of errors (usually including the line numbers). In the case of your cgi, you'll get an error saying something like Global symbol "$test" requires explicit package name at - line 9. which is a whole lot more helpful than the error you were getting.

    Another useful command is to do perl -c myfile.pl which will tell you if your code will compile.

    my @a=qw(random brilliant braindead); print $a[rand(@a)];

Re: CGI::Carp won't send fatalsToBrowser
by converter (Priest) on Dec 12, 2001 at 21:52 UTC

    If I understand your complaint, scripts that formerly sent fatal errors to STDOUT with mark-up now send fatal errors to STDERR.

    Another monk gave you a good piece of advice: run the program from the command line. If you see something like the output from the one-liner included below, then you'll know that CGI::Carp is doing what it's supposed to. If not, then something is probably broken somewhere (how helpful is that?!).

    Have any of the modules you're using been been upgraded recently? What about perl? Have there been any changes to the server software or configuration? Are there other users you could check with to see if they're experiencing the same problem?

    $ perl -Mstrict -wle 'use CGI qw/:standard/; use CGI::Carp qw/fatalsTo +Browser/; print header, h1("hello"); $test = 1' Content-type: text/html <H1>Software error:</H1> <PRE>Global symbol &quot;$test&quot; requires explicit package name at + -e line 1. Execution of -e aborted due to compilation errors. </PRE> <P> For help, please send mail to this site's webmaster, giving this error + message and the time and date of the error. [Wed Dec 12 10:44:45 2001] -e: Global symbol "$test" requires explicit + package name at -e line 1. [Wed Dec 12 10:44:45 2001] -e: Execution of -e aborted due to compilat +ion errors.

    conv

      Thanks... alas, I don't have command line access - it's an ISP. It may well be that they made some changes to some modules. I'll try and find out. I am getting Carp-style output to the error log, so something is going right. I know this because my error log looks different if I turn CGI::Carp off. It's just that the output is now not getting into the browser. But I'm reassured to know that I may not be going mad after all :)

      § George Sherston
(tye)Re: CGI::Carp won't send fatalsToBrowser
by tye (Sage) on Dec 12, 2001 at 23:56 UTC

    I suspect this may be dependant on the version of CGI::Carp and/or version of Perl being used (I suspect the latter). My testing shows both lines of error information going to the browser.

            - tye (but my friends call me "Tye")
Re: CGI::Carp won't send fatalsToBrowser
by cLive ;-) (Prior) on Dec 12, 2001 at 23:42 UTC
    rewrite - spotted something obvious the second I posted. This seems to work:
    #!/usr/bin/perl -w use strict; print "Content-type: text/plain\n\n"; eval { require 'foo.pl'; } if ($@) { print "ERROR:\n\n$@"; } else { print "OUTPUT:\n\n"; print `perl foo.pl`; # that's `, not ' }

    hth

    cLive ;-)

      I'm probably being thick... but is this in the right thread? If so, cd you elucidate it a little bit for me?

      § George Sherston
        All I meant was, if CGI::Carp doesn't seem to work, this little snippet might help. ie. upload it into the same directory, amending the 'foo.pl' (x2) as necessary and look at the output in your browser. Since it evals the script, it traps the error and allows you to send it to the browser.

        cLive ;-)

        ps - if you need more inffo on this, why not /msg me...