FAQ
I was surprised to discover that when a chained action throws a fatal
error, Catalyst continues executing the remaining actions in the
chain. Personally, I had assumed that each action in the chain could
depend on the preceeding actions having been executed successfully.

I've looked at the code in Catalyst::ActionChain, Catalyst::Action,
and Catalyst, so I see how this happens, but I'm not sure it's what
should happen. Is this the desired behavior?


Here's an example:

sub root : Chained('/') PathPart('chain') CaptureArgs(0) {
my ($self, $c) = @_;

die "Oops!";

$c->stash->{'greeting'} = 'Hello';
}

sub node : Chained('root') PathPart('') CaptureArgs(0) {
my ($self, $c) = @_;

die "Oops!";

$c->stash->{'name'} = 'world';
}

sub test : Chained('node') PathPart('') Args(0) {
my ($self, $c) = @_;

$c->stash->{'message'} =
$c->stash->{'greeting'} . ' ' . $c->stash->{'name'} . '!';

$c->res->body($c->stash->{'message'});
}


Use of uninitialized value in concatenation (.) or string at
lib/ChainTest/Controller/Root.pm line 67.
Use of uninitialized value in concatenation (.) or string at
lib/ChainTest/Controller/Root.pm line 67.
[info] *** Request 1 (1.000/s) [19323] [Thu Apr 7 13:52:19 2011] ***
[debug] "GET" request for "chain" from "127.0.0.1"
[debug] Path is "/test"
[error] Caught exception in ChainTest::Controller::Root->root "Oops!
at lib/ChainTest/Controller/Root.pm line 51."
[error] Caught exception in ChainTest::Controller::Root->node "Oops!
at lib/ChainTest/Controller/Root.pm line 59."
[debug] Response Code: 500; Content-Type: text/html; charset=utf-8;
Content-Length: 7078
[info] Request took 0.028427s (35.178/s)
.------------------------------------------------------------+-----------.
Action | Time |
+------------------------------------------------------------+-----------+
/root | 0.000252s |
/node | 0.000113s |
/test | 0.000216s |
/end | 0.000469s |
'------------------------------------------------------------+-----------'


The test() action assumes that $c->stash->{'greeting'} and
$c->stash->{'name'} have been set. In this example it's fairly
innocuous, but what if test() was doing something like updating a
database based on those supposed values?

Ronald

Search Discussions

  • Dami Laurent (PJ) at Apr 8, 2011 at 9:39 am

    -----Message d'origine-----
    De?: Ronald J Kimball
    Envoy??: jeudi, 7. avril 2011 20:11
    ??: The elegant MVC web framework
    Objet?: [Catalyst] Fatal errors in chained actions

    I was surprised to discover that when a chained action throws a fatal
    error, Catalyst continues executing the remaining actions in the
    chain. Personally, I had assumed that each action in the chain could
    depend on the preceeding actions having been executed successfully.
    Hi Ronald,

    This point was discussed in 2008 : see
    http://lists.scsys.co.uk/pipermail/catalyst/2008-March/017748.html
    and the rest of the thread.

    At that time I also had some IRC chats or private e-mails with Matt Trout about this point; he of course suggested me to write a patch ... which I never did !
    The problem we discussed was that a change of behaviour would perhaps break some stuff in existing applications; so what is probably needed is a parameter somewhere in Catalyst config to tune the error handling for chained actions.

    For the moment, what I do in my applications is quite bad : load Catalyst::ActionChain and forcefully overwrite the dispatch() method, applying the code change proposed in
    http://lists.scsys.co.uk/pipermail/catalyst/2008-March/017789.html
    I really need that hack because, as you mention, if a database call fails in the first URL segment, we better stop there instead of applying the following segments.

    So maybe it's time to really think about proposing a patch to Catalyst ...

    Best regards, Laurent Dami
  • Ashley Pond V at Apr 8, 2011 at 2:22 pm

    On Fri, Apr 8, 2011 at 2:39 AM, Dami Laurent (PJ) wrote:
    -----Message d'origine-----
    De?: Ronald J Kimball
    Envoy??: jeudi, 7. avril 2011 20:11
    ??: The elegant MVC web framework
    Objet?: [Catalyst] Fatal errors in chained actions

    I was surprised to discover that when a chained action throws a fatal
    error, Catalyst continues executing the remaining actions in the
    chain. ?Personally, I had assumed that each action in the chain could
    depend on the preceeding actions having been executed successfully.
    Hi Ronald,

    This point was discussed in 2008 : see
    http://lists.scsys.co.uk/pipermail/catalyst/2008-March/017748.html
    and the rest of the thread.
    It was actually discussed a year before that:
    http://lists.scsys.co.uk/pipermail/catalyst/2007-July/014507.html

    The idea suffered from similar lack of tuits at the time.

    -Ashley

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupcatalyst @
categoriescatalyst, perl
postedApr 7, '11 at 6:10p
activeApr 8, '11 at 2:22p
posts3
users3
websitecatalystframework.org
irc#catalyst

People

Translate

site design / logo © 2021 Grokbase