Skip to content

Commit

Permalink
Storing StackTrace object in $env causes a circular reference.
Browse files Browse the repository at this point in the history
The "real" fix for this would be to have an option or method to walk
over StackTrace frame and weaken() all args and lexicals (in case of
WithLexicals) so that the trace object can be safely stored in $env,
but for now, storing text version of the trace and HTML version would
be enough.
  • Loading branch information
miyagawa committed Oct 25, 2010
1 parent 6de0f92 commit f1b7d33
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
15 changes: 8 additions & 7 deletions lib/Plack/Middleware/StackTrace.pm
Expand Up @@ -28,10 +28,12 @@ sub call {

if ($trace && ($caught || ($self->force && ref $res eq 'ARRAY' && $res->[0] == 500)) ) {
my $text = trace_as_string($trace);
$env->{'plack.stacktrace'} = $trace;
my $html = $trace->as_html;
$env->{'plack.stacktrace.text'} = $text;
$env->{'plack.stacktrace.html'} = $html;
$env->{'psgi.errors'}->print($text) unless $self->no_print_errors;
if (($env->{HTTP_ACCEPT} || '*/*') =~ /html/) {
$res = [500, ['Content-Type' => 'text/html; charset=utf-8'], [ utf8_safe($trace->as_html) ]];
$res = [500, ['Content-Type' => 'text/html; charset=utf-8'], [ utf8_safe($html) ]];
} else {
$res = [500, ['Content-Type' => 'text/plain; charset=utf-8'], [ utf8_safe($text) ]];
}
Expand Down Expand Up @@ -91,11 +93,10 @@ Plack::Middleware::StackTrace - Displays stack trace when your app dies
=head1 DESCRIPTION
This middleware catches exceptions (run-time errors) happening in your
application and displays nice stack trace screen. The stack trace
(L<Devel::StackTrace> or L<Devel::StackTrace::WithLexicals> object,
depending on which library you have installed) is also stored in the
environment under the key C<plack.stacktrace> so that middleware
futher up the stack can reference it.
application and displays nice stack trace screen. The stack trace is
also stored in the environment as a plaintext and HTML under the key
C<plack.stacktrace.text> and C<plack.stacktrace.html> respectively, so
that middleware futher up the stack can reference it.
This middleware is enabled by default when you run L<plackup> in the
default I<development> mode.
Expand Down
2 changes: 1 addition & 1 deletion t/Plack-Middleware/stacktrace.t
Expand Up @@ -9,7 +9,7 @@ my $traceapp = Plack::Middleware::StackTrace->wrap(sub { die "orz" }, no_print_e
my $app = sub {
my $env = shift;
my $ret = $traceapp->($env);
like $env->{'plack.stacktrace'}->as_string, qr/orz/;
like $env->{'plack.stacktrace.text'}, qr/orz/;
return $ret;
};

Expand Down

0 comments on commit f1b7d33

Please sign in to comment.