using CGI::Carp

Discussion in 'Perl Misc' started by Moritz Karbach, Apr 26, 2005.

  1. 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
    Moritz Karbach, Apr 26, 2005
    #1
    1. Advertising

  2. Moritz Karbach wrote:
    > 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.

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
    Gunnar Hjalmarsson, Apr 26, 2005
    #2
    1. Advertising

  3. 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
    Moritz Karbach, Apr 26, 2005
    #3
  4. Moritz Karbach

    Nikos Guest

    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.
    Nikos, Apr 26, 2005
    #4
  5. Moritz Karbach wrote:
    >> 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.


    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.

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
    Gunnar Hjalmarsson, Apr 26, 2005
    #5
  6. 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
    Moritz Karbach, Apr 26, 2005
    #6
  7. Gunnar Hjalmarsson wrote:

    > 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
    Moritz Karbach, Apr 26, 2005
    #7
  8. Moritz Karbach

    Nikos Guest

    Moritz Karbach wrote:
    > 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.
    Nikos, Apr 26, 2005
    #8
  9. [solved] Re: using CGI::Carp

    Hi,

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

    Thanks for your help,

    - Moritz
    Moritz Karbach, Apr 26, 2005
    #9
  10. Moritz Karbach <> wrote:
    > Gunnar Hjalmarsson wrote:
    >
    >> 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.



    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?


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
    Tad McClellan, Apr 26, 2005
    #10
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Louis Erickson
    Replies:
    2
    Views:
    205
    James Willmore
    Sep 3, 2003
  2. Jo Oberman
    Replies:
    5
    Views:
    214
    Ilya Zakharevich
    Sep 14, 2003
  3. Gunnar Hjalmarsson

    CGI::Carp and "useless quotes"

    Gunnar Hjalmarsson, Apr 4, 2004, in forum: Perl Misc
    Replies:
    12
    Views:
    204
    Gunnar Hjalmarsson
    Apr 16, 2004
  4. bernd

    CGI::Carp die with status

    bernd, Feb 5, 2008, in forum: Perl Misc
    Replies:
    6
    Views:
    172
  5. Bennett Haselton
    Replies:
    2
    Views:
    521
    Gunnar Hjalmarsson
    Mar 2, 2008
Loading...

Share This Page