RE: Compiler errors...

2000-04-17 Thread Robert Jenks
Title: RE: Compiler errors...





Well this does work better, but as I found out, it doesn't solve my problem.  While this does catch runtime errors, it doesn't catch compile-time errors when using Apache::StatINC.  

However thanks to your hint on how to do this, I was able to patch Apache::StatINC to display the compile-time errors for me.

In Apache::StatINC:


I replaced:
        require $key;


With:
        eval {
            require $key;
        };
        if ($@ && $DEBUG) {
            $r->content_type('text/html');
                $r->send_http_header();
                $r->print("Perl Compiler Errors:");
                $r->print($@);
            $r->print("");
        }


With this, and the eval{} wrapper around the regular PerlHandler (below), I've got all error messages displaying to the browser (I think :-)

Of course, there is still the issue of non-fatal warning messages not being displayed to the browser.  However, unless someone has an idea how to do that, I'll live without it.

Thanks for the help...
-Robert



-Original Message-
From: Ken Y. Clark [mailto:[EMAIL PROTECTED]]
Sent: Friday, April 14, 2000 8:40 PM
To: modperl (E-mail)
Subject: Re: Compiler errors...



On Fri, 14 Apr 2000, Robert Jenks wrote:


> We are currently using Linux/Apache/mod_perl (and Stat::INC) with good
> success (thanks to the help of this list) as a replacement for
> WinNT/IIS/Velocigen.  Everything is (now) going good except that we miss one
> of Velocigen's debugging features.  Velocigen would display compiler errors
> to the browser (after a file-change recompile).  
> 
> I'm currently using CGI::Carp qw(fatalsToBrowser), but this only shows
> runtime errors.
> 
> Is there a way to do this?  I've thought about using the Apache
> "ErrorDocument" config to call a perl script which would display the last
> few lines of the error_log, but it wouldn't be very elegant.


robert,


i would suggest wrapping all the meat of you code in an eval, and then
checking for errors on exit.  when things go wrong, you handle the error.
when things are fine, you create output, like so:


package Foo::Bar;


use Apache;
use Apache::Constants qw(:common);
use strict;


sub handler {
    my $r = shift;
   
    eval {
    # put anything here that could possibly error out
    # like database connections, file reads, etc.
    };


    $r->content_type('text/html');
    $r->send_http_header;


    if ($@) {
    $r->print("There was an error: '$@'");
    } else {
    $r->print('Apache/mod_perl rules!');
    }
    return OK;
}


1;


hth,


ky





RE: Compiler errors...

2000-04-14 Thread Robert Jenks
Title: RE: Compiler errors...





Thanks Ken!  It worked like a charm!


-Robert





Re: Compiler errors...

2000-04-14 Thread Ken Y. Clark

On Fri, 14 Apr 2000, Robert Jenks wrote:

> We are currently using Linux/Apache/mod_perl (and Stat::INC) with good
> success (thanks to the help of this list) as a replacement for
> WinNT/IIS/Velocigen.  Everything is (now) going good except that we miss one
> of Velocigen's debugging features.  Velocigen would display compiler errors
> to the browser (after a file-change recompile).  
> 
> I'm currently using CGI::Carp qw(fatalsToBrowser), but this only shows
> runtime errors.
> 
> Is there a way to do this?  I've thought about using the Apache
> "ErrorDocument" config to call a perl script which would display the last
> few lines of the error_log, but it wouldn't be very elegant.

robert,

i would suggest wrapping all the meat of you code in an eval, and then
checking for errors on exit.  when things go wrong, you handle the error.
when things are fine, you create output, like so:

package Foo::Bar;

use Apache;
use Apache::Constants qw(:common);
use strict;

sub handler {
my $r = shift;
   
eval {
# put anything here that could possibly error out
# like database connections, file reads, etc.
};

$r->content_type('text/html');
$r->send_http_header;

if ($@) {
$r->print("There was an error: '$@'");
} else {
$r->print('Apache/mod_perl rules!');
}
return OK;
}

1;

hth,

ky