On Saturday, September 10, 2016 at 12:40:47 PM UTC-7, Aristotle Pagaltzis 
wrote:
>
> * Abelard <abelard...@gmail.com <javascript:>> [2016-09-10 08:12]: 
> > On Friday, September 9, 2016 at 9:44:51 PM UTC-7, Aristotle Pagaltzis 
> wrote: 
> > > Are you looking for something like this? 
> > > 
> > >     my $old_die_handler = $SIG{__DIE__}; 
> > >     local $SIG{__DIE__} = sub { 
> > >         $_[0] .= " lots of details about system state"; 
> > >         ref $old_die_handler ? goto &$old_die_handler : die @_; 
> > >     }; 
> > >     dispatch();  # no eval{} 
> > 
> > Yes! Exactly like that. Except for this: 
> > 
> >   Modification of a read-only value attempted at ./try line 13. 
> > 
> > Is there a way around that? 
>
> Err, of course? Presumably something like this: 
>
>     { 
>         my $old_die_handler = $SIG{__DIE__}; 
>         local $SIG{__DIE__} = sub { 
>             my $msg = shift; 
>             unshift @_, $msg . " lots of details about system state"; 
>             ref $old_die_handler ? goto &$old_die_handler : die @_; 
>         }; 
>         dispatch(); 
>     } 
>
> (Just as untested as my previous scribble.) (E.g. this time I remembered 
> to add a block to limit the scope of the `local`.) 
>

I'm seeing an infinite loop with that.  Here's a self-contained test, run as
"plackup -MPlack::Middleware::StackTrace ./hello.psgi"

use strict;
use warnings;

my $app = sub {
  my $old_die_handler = $SIG{__DIE__};

  local $SIG{__DIE__} = sub {
    # warn "my die called from ", caller, "\n";

    my $msg = shift;
    unshift @_, $msg . " lots of details about system state";
    ref $old_die_handler ? goto &$old_die_handler : die @_;
  };

  die "goodbye world!";
  # return [ 200, [ 'Content-Type' => 'text/plain' ], [ 'Hello World' ] ];
};

With the new DIE handler commented out, it works. Once I add that,
I get "deep recursion" error and out of memory failure.

Adding in the "warn" there, I see it's getting called repeatedly by the
StackTrace middleware.

Does a goto from a DIE handler prevent the disabling of handler.  perlvar 
says

> The "__DIE__" handler is explicitly disabled during the call, so that you 
> can die
> from a "__DIE__" handler.

but I don't understand why it's continuing calling my die routine then... 
 

> * Abelard <abelard...@gmail.com <javascript:>> [2016-09-10 08:36]: 
> > Here's a patch to Plack::Middleware::StackTrace that seems to work, 
>
> You don’t want that. 
>
> The __DIE__ handler gets called for any and all exceptions. During 
> unwind there can be other caught-and-handled exceptions after the 
> __DIE__ handler is called but before the eval{} returns, and the __DIE__ 
> handler will be called for all of those too. If you only keep the stack 
> trace for the last thrown exception, that won’t necessarily match the 
> exception caught by the eval{} block. 
>

Yes, I saw that. I was thinking as long as you don't do anything between 
the eval and the reraise, that you'd get the right trace, but I guess not. 
My first approach was to provide aliases (e.g., new_error => old_error) so 
that StackTrace could follow the chain, but it seemed so complicated.

Obviously I'd rather just get your code working :)

Thanks.

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"psgi-plack" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to psgi-plack+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to