[Catalyst] Error handling

J. Shirley jshirley at gmail.com
Tue Jan 19 03:50:49 GMT 2010


On Mon, Jan 18, 2010 at 5:44 PM, Steve Kleiman <steve at prodhub.com> 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



More information about the Catalyst mailing list