On Fri, Sep 9, 2016 at 9:18 AM, Abelard <abelardhoff...@gmail.com> wrote:
> Hi.
>
> I have an app that catches exceptions and appends data to it. In
> development, I'd like to use Plack::Middleware::StackTrace to display the
> trace. However, since I'm rethrowing a modified error message, it isn't
> finding the Devel::StraceTrack that was built.
>
> For example, I'm doing something along these lines:
>
> eval { dispatch() };
> if (my $error = $@) {
>   $error .= " lots of details about system state";
>   die $error;
> }
>
> From my understanding of P::M::ST, the $SIG{DIE} handler is being trigged
> when the exception is raised in the eval. It's building the stack trace off
> of that, which is what I want.
> Then I go fiddling with the error and re-raise it. Since the error has been
> changed it doesn't match anything in %string_traces, resulting in the real
> backtrace being lost.
>
> Is there a way around that?
>
> I found Plack::Middleware::RethrowFriendly, but I'm not sure if it's
> intended to handle this case. I tried it and it didn't seem to show the
> backtrace from within the eval.
>
> I was thinking that if I can modify $@ before the $SIG{DIE} handler gets it,
> maybe that would work, but I'm not sure how to do that.
>
> Thanks -A

This is not Plack specific, but in general in Perl:

my $stack;
local $SIG{__DIE__} = sub { $stack = longmess() };
eval { code(); 1 }
or do {
    my $error = $@ || "Zombie Error";
    say "You had an error with stack $stack";
};

You probably want to chop off the stack bits that land you in the
__DIE__ handler itself, and this gets quite tricky in some situations.

-- 

--- 
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