using CGI::Carp

M

Moritz Karbach

Hi all,

I'd like to appear all errors (syntax, file inclusion, ...) of my CGI script
in the browser. A quick googling told me to do

BEGIN
{
$|=1;
print "Content-Type: text/html; charset=ISO-8859-1\n\n";
use CGI::Carp('fatalsToBrowser');
# or use CGI::Carp qw(fatalsToBrowser warningsToBrowser);
}

The result is, that the Internal Server Error dissappears (due to the
correct header), but still no errors are sent to the browser.

Also a

BEGIN
{
use CGI::Carp qw(carpout);
print "Content-Type: text/html; charset=ISO-8859-1\n\n";
carpout(STDOUT);
}

didn't work (still error 500).

Any ideas?

- Moritz
 
G

Gunnar Hjalmarsson

Moritz said:
I'd like to appear all errors (syntax, file inclusion, ...) of my CGI script
in the browser. A quick googling told me to do

BEGIN
{
$|=1;
print "Content-Type: text/html; charset=ISO-8859-1\n\n";
use CGI::Carp('fatalsToBrowser');
# or use CGI::Carp qw(fatalsToBrowser warningsToBrowser);
}

Have you tried to just say:

use CGI::Carp 'fatalsToBrowser';

You don't need to print any content-type header there, since CGI::Carp
takes care of that if it catches an error.
The result is, that the Internal Server Error dissappears (due to the
correct header), but still no errors are sent to the browser.

Please show us a short but complete program (with a fatal error) that
does not behave as you would have expected.
 
M

Moritz Karbach

Hi Gunnar,
Have you tried to just say:

use CGI::Carp 'fatalsToBrowser';

Yes, I have - same problem.
Please show us a short but complete program (with a fatal error) that
does not behave as you would have expected.

Ok then:

<---- error.pl ---->
#!/usr/bin/perl -w

BEGIN
{
use CGI::Carp('fatalsToBrowser');
}

print "Content-Type: text/html; charset=ISO-8859-1\n\n";

printt "<h1>Hello World</h1>"; # typo in print
</---- error.pl ---->


This gives an 500 error. When I execute it on the command shell I get


$ ./error.pl
[Tue Apr 26 15:18:15 2005] error.pl: Unquoted string "printt" may clash with
future reserved word at ./error.pl line 10.
[Tue Apr 26 15:18:15 2005] error.pl: String found where operator expected at
../error.pl line 10, near "printt "<h1>Hello World</h1>""
[Tue Apr 26 15:18:15 2005] error.pl: (Do you need to predeclare printt?)
syntax error at ./error.pl line 10, near "printt "<h1>Hello World</h1>""
Execution of ./error.pl aborted due to compilation errors.


If I correct the typo it runs perfectly well, so I assume my webserver is
configured correctly, at least more or less. I have root on the webserver,
so in case there is something misconfigured please tell.

Cheers,

- Moritz
 
N

Nikos

Gunnar Hjalmarsson wrote:

Thats how i use the Carp Moduel and it wokrs fine:

use CGI qw:)standard);
use CGI::Carp qw(fatalsToBrowser);

Try that.
 
G

Gunnar Hjalmarsson

Moritz said:
Ok then:

<---- error.pl ---->
#!/usr/bin/perl -w

BEGIN
{
use CGI::Carp('fatalsToBrowser');
}

print "Content-Type: text/html; charset=ISO-8859-1\n\n";

printt "<h1>Hello World</h1>"; # typo in print
</---- error.pl ---->

This gives an 500 error.

That's odd.

Maybe you should try to upgrade CGI::Carp (provided that you don't have
the latest version...) and see if that makes a difference.
 
M

Moritz Karbach

Hi Niko,

<---- error.pl ---->
#!/usr/bin/perl -w

BEGIN
{
use CGI qw:)standard);
use CGI::Carp('fatalsToBrowser');
}

print "Content-Type: text/html; charset=ISO-8859-1\n\n";

printt "<h1>Hello World</h1>"; # typo in print
</---- error.pl ---->


gives only a 500 again.

- Moritz
 
M

Moritz Karbach

Gunnar said:
Maybe you should try to upgrade CGI::Carp (provided that you don't have
the latest version...) and see if that makes a difference.

Well ok then - I could use a little help with that.

1. I guess my server is a Red Hat distri.
2. How do I check the version of CGI::Carp?
3. How do I update it?

- Moritz
 
N

Nikos

Moritz said:
Hi Niko,

<---- error.pl ---->
#!/usr/bin/perl -w

BEGIN
{
use CGI qw:)standard);
use CGI::Carp('fatalsToBrowser');
}

print "Content-Type: text/html; charset=ISO-8859-1\n\n";

printt "<h1>Hello World</h1>"; # typo in print
</---- error.pl ---->


gives only a 500 again.

- Moritz

I see, well, that certainly would have to work but if it does not then
somethign is wrong with your Perl Installation or you definately need to
update to the latest CGI::Carp module.
 
M

Moritz Karbach

Hi,

finally I figured out how to update the module. And it works :)

Thanks for your help,

- Moritz
 
T

Tad McClellan

Moritz Karbach said:
Well ok then - I could use a little help with that.

1. I guess my server is a Red Hat distri.


That is irrelevant.

2. How do I check the version of CGI::Carp?


perl -MCGI::Carp -e 'print $CGI::Carp::VERSION'

3. How do I update it?


Please refrain from repeating Frequently Asked Questions.

perldoc -q module

What modules and extensions are available for Perl? What is CPAN?
What does CPAN/src/... mean?

How do I install a module from CPAN?

How do I keep my own module/library directory?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top