[cgiapp] Problems with exception handling in CAP::Dispatch

Ron Savage ron at savage.net.au
Tue May 15 19:10:21 EDT 2012


Hi Michael

On 16/05/12 00:17, Michael Lackhoff wrote:
> There seems to be something wrong (or at least not very robust) in
> CAP::Dispatch::http_error(). It has the following code:
>
>      warn '[Dispatch] ERROR'
>        . ($ENV{REQUEST_URI} ? " for request '$ENV{REQUEST_URI}': " : ': ')
>        . $e->error . "\n";
>
> I guess $e is expected to be an Exception::Class object with an error
> method but when a run mode dies the error seems to be passed as a string
> not an object. So it dies again at this line in http_error with the
> following log message (line numbers slightly different due to a few
> added debug statements):

Yes - I remember struggling with this when I forked CGI:App and 
CGI::App::Dispatch to produce CGI::Snapp and CGI::Snapp::Dispatch.

The problem starts with CAP::Dispatch V 2.18 line 406:
         $output = $self->_run_app($module, $rm, $local_args_to_new);
which at least tells you the app got as far as starting.

In V 3.07, that's line 405.

Then, in _run_app(), lines 713 .. 716 say:
               # otherwise, just pass it up the chain
         } else {
             die $@;
         }
which tells you the code /in this case/ does not call throw_*.

And in V 3.07 that's lines 716 .. 719.

Conclusion: Either way, you're stuffed :-(.

If you don't want to switch to CGI::Snapp etc, or can't, I'd suggest not 
relying on that exception code at all.

Rather: Just do what I did with the re-writes: Add logging code at the 
start of all the major subs, which will simply if crudely tell you 
exactly how far the code is getting before it dies.

HTH

-- 
Ron Savage
http://savage.net.au/
Ph: 0421 920 622


More information about the cgiapp mailing list