FAQ
Thanks for all the feedback on how to log from within a schema. Log4perl is my hero.

I'm still looking for a way to capture runtime errors and ideally email them out in addition to logging to a file.

I've tried Catalyst-Action-RenderView-ErrorHandler but that seems to have no impact. I see the error on the console as usual but I don't get an email dispatched nor the expected error page. Maybe I've got it misconfigured? It seems like exactly what I want.

Same thing with Catalyst::Plugin::ErrorCatcher. Doesn't seem to catch runtime errors.

Found a post on this mailing list suggesting:

sub finalize_error {
my ($c) = @_; # Note, not ($self, $c)

if ( @{$c->errors} ) {
$c->stash->template('error.tt');
# You might also need to forward to the view here yourself
return;
}
$c->NEXT::finalize_error();
}

But the error seems to abort all processing and never make it to this point.

Ideally the mechanism would trap ALL errors in controllers and also the schema.

I must be doing something wrong. Where am I off base?

Thanks in advance.

-steve kleiman

Search Discussions

  • Tomas Doran at Jan 18, 2010 at 5:21 pm

    Steve Kleiman wrote:
    Found a post on this mailing list suggesting:

    sub finalize_error {
    my ($c) = @_; # Note, not ($self, $c)

    if ( @{$c->errors} ) {
    $c->stash->template('error.tt');
    # You might also need to forward to the view here yourself
    return;
    }
    $c->NEXT::finalize_error();
    }

    But the error seems to abort all processing and never make it to this point.
    I don't see why that's happening - can you explain what you mean by
    'abort all processing'?

    The most common reason for custom error handlers not working is that
    people forget to call $c->clear_error...

    Cheers
    t0m
  • Steve Kleiman at Jan 19, 2010 at 1:44 am
    Thanks for getting back, t0m.

    By "abort all processing" it seemed like when the error was thrown, Catalyst stopped processing the request.

    Here's my fabricated error in a controller:
    sub test_error : Local {
    my ( $self, $c ) = @_;
    Log::Log4perl->get_logger('General')->info('before error');
    $c->nonexistent_method;
    Log::Log4perl->get_logger('General')->info('after error');
    $c->response->body('Got past error');
    }
    Thanks to log4perl, I see the request seemingly hits 'end' before the error is registered (see console log below).

    I also have a log line in 'finalize_error' but it never gets hit.

    I tried putting '$c->clear_errors' in my 'end' method, but then the error doesn't print to console at all.

    I'm missing something....

    -steve


    2010/01/18 17:33:16 Root.pm 100> auto
    2010/01/18 17:33:16 Administration.pm 55> before error
    2010/01/18 17:33:16 Root.pm 148> end
    [info] *** Request 2 (0.002/s) [5404] [Mon Jan 18 17:33:16 2010] ***
    [debug] "GET" request for "app/project/administration/test_error" from "127.0.0.1"
    [debug] Path is "app/project/administration/test_error"
    [debug] Found sessionid "a6868e20c5ff9800b88e1a6ac7eef75ec4e9a8c4" in cookie
    [debug] Restored session "a6868e20c5ff9800b88e1a6ac7eef75ec4e9a8c4"
    [debug] running ACL rule CODE(0x1027c0438) defined at /Users/smk/enola/ProdHub/tech/prodhub/prodhub/script/../lib/Prodhub.pm line 307 on app/project/administration/test_error
    [debug] Access to app/project/administration/test_error allowed by rule CODE(0x1027c0438) (defined at /Users/smk/enola/ProdHub/tech/prodhub/prodhub/script/../lib/Prodhub.pm line 307)
    [error] Caught exception in Prodhub::Controller::App::Project::Administration->test_error "Can't locate object method "nonexistent_method" via package "Prodhub" at /Users/smk/enola/ProdHub/tech/prodhub/prodhub/script/../lib/Prodhub/Controller/App/Project/Administration.pm line 56."
    [error] Caught exception in engine "Can't use string ("a6868e20c5ff9800b88e1a6ac7eef75e") as a HASH ref while "strict refs" in use at /usr/local/lib/perl5/site_perl/5.10.1/Catalyst/Engine.pm line 117."

    On Jan 18, 2010, at 9:22 AM, Tomas Doran wrote:

    Steve Kleiman wrote:
    Found a post on this mailing list suggesting:
    sub finalize_error {
    my ($c) = @_; # Note, not ($self, $c)
    if ( @{$c->errors} ) {
    $c->stash->template('error.tt');
    # You might also need to forward to the view here yourself
    return;
    }
    $c->NEXT::finalize_error();
    }
    But the error seems to abort all processing and never make it to this point.
    I don't see why that's happening - can you explain what you mean by 'abort all processing'?

    The most common reason for custom error handlers not working is that people forget to call $c->clear_error...

    Cheers
    t0m
  • Jay Shirley at Jan 19, 2010 at 3:50 am

    On Mon, Jan 18, 2010 at 5:44 PM, Steve Kleiman wrote:
    Thanks for getting back, t0m.

    By "abort all processing" it seemed like when the error was thrown, Catalyst stopped processing the request.

    Here's my fabricated error in a controller:
    sub test_error : Local {
    ? ? ? my ( $self, $c ) = @_;
    ? ? ? Log::Log4perl->get_logger('General')->info('before error');
    ? ? ? $c->nonexistent_method;
    ? ? ? Log::Log4perl->get_logger('General')->info('after error');
    ? ? ? $c->response->body('Got past error');
    }
    Thanks to log4perl, I see the request seemingly hits 'end' before the error is registered (see console log below).

    I also have a log line in 'finalize_error' but it never gets hit.

    I tried putting '$c->clear_errors' in my 'end' method, but then the error doesn't print to console at all.

    I'm missing something....

    -steve


    2010/01/18 17:33:16 Root.pm 100> auto
    2010/01/18 17:33:16 Administration.pm 55> before error
    2010/01/18 17:33:16 Root.pm 148> end
    [info] *** Request 2 (0.002/s) [5404] [Mon Jan 18 17:33:16 2010] ***
    [debug] "GET" request for "app/project/administration/test_error" from "127.0.0.1"
    [debug] Path is "app/project/administration/test_error"
    [debug] Found sessionid "a6868e20c5ff9800b88e1a6ac7eef75ec4e9a8c4" in cookie
    [debug] Restored session "a6868e20c5ff9800b88e1a6ac7eef75ec4e9a8c4"
    [debug] running ACL rule CODE(0x1027c0438) defined at /Users/smk/enola/ProdHub/tech/prodhub/prodhub/script/../lib/Prodhub.pm line 307 on app/project/administration/test_error
    [debug] Access to app/project/administration/test_error allowed by rule CODE(0x1027c0438) (defined at /Users/smk/enola/ProdHub/tech/prodhub/prodhub/script/../lib/Prodhub.pm line 307)
    [error] Caught exception in Prodhub::Controller::App::Project::Administration->test_error "Can't locate object method "nonexistent_method" via package "Prodhub" at /Users/smk/enola/ProdHub/tech/prodhub/prodhub/script/../lib/Prodhub/Controller/App/Project/Administration.pm line 56."
    [error] Caught exception in engine "Can't use string ("a6868e20c5ff9800b88e1a6ac7eef75e") as a HASH ref while "strict refs" in use at /usr/local/lib/perl5/site_perl/5.10.1/Catalyst/Engine.pm line 117."
    Hi Steve,

    First (and you missed my talk at Perl Oasis where I actually went over
    this!) to address the original question, I've been using
    Catalyst::Plugin::ErrorCatcher with great success. Works as expected.
    You can see more at:
    http://search.cpan.org/dist/Catalyst-Plugin-ErrorCatcher

    As for what you are seeing, I'd have to see your end action. If you
    put clear_errors, nothing will be printed out. Think of that as an
    eval { } where you throw away $@.

    What you can do is:

    $c->log->_dump( $c->errors );
    $c->clear_errors;

    That will show you the errors, and I believe get you what you expect
    to see. Having said all that, I am fond of ErrorCatcher, and use its
    included Email emitter quite happily.

    Thanks,
    -J
  • Wes Cravens at Jan 20, 2010 at 6:52 pm

    J. Shirley wrote:
    That will show you the errors, and I believe get you what you expect
    to see. Having said all that, I am fond of ErrorCatcher, and use its
    included Email emitter quite happily.
    I am currently attempting to use ErrorCatcher to send email but also
    have a custom error page be rendered. I've tried the Cookbook 'end'
    method in Root but clearing the error there seems to prevent
    ErrorCatcher from reacting, but letting it fall through gives me the
    'Please come back later' page.

    Is there a suitable way to have both ErrorCatcher and a custom error
    page? I'm trying to resist writing an ErrorCatcher emitter just for this.

    Wes
  • Jay Shirley at Jan 20, 2010 at 7:22 pm

    On Wed, Jan 20, 2010 at 10:52 AM, Wes Cravens wrote:
    J. Shirley wrote:
    That will show you the errors, and I believe get you what you expect
    to see. ?Having said all that, I am fond of ErrorCatcher, and use its
    included Email emitter quite happily.
    I am currently attempting to use ErrorCatcher to send email but also have a
    custom error page be rendered. ?I've tried the Cookbook 'end' method in Root
    but clearing the error there seems to prevent ErrorCatcher from reacting,
    but letting it fall through gives me the 'Please come back later' page.

    Is there a suitable way to have both ErrorCatcher and a custom error page?
    ?I'm trying to resist writing an ErrorCatcher emitter just for this.

    I am using Catalyst::Plugin::CustomErrorMessage in conjunction with
    ErrorCatcher -- works like a charm.

    -J
  • Bill Moseley at Jan 21, 2010 at 4:33 am

    On Mon, Jan 18, 2010 at 9:05 AM, Steve Kleiman wrote:

    Thanks for all the feedback on how to log from within a schema. Log4perl is
    my hero.

    I'm still looking for a way to capture runtime errors and ideally email
    them out in addition to logging to a file.
    I use log4perl to send "error" level messages to an additional log file.
    Then I use cron to check for errors every few minutes and send a
    notification email. I like that better than the possibility of hundreds of
    processes cranking out mail at the same time.

    The plan is to move to a logging server to centralize this a bit more.




    --
    Bill Moseley
    moseley@hank.org
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20100120/b7ca2513/attachment.htm

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupcatalyst @
categoriescatalyst, perl
postedJan 18, '10 at 5:05p
activeJan 21, '10 at 4:33a
posts7
users5
websitecatalystframework.org
irc#catalyst

People

Translate

site design / logo © 2021 Grokbase