Permalink
Browse files

Remove the automatically added ' at {file} line {line}.' from a throw…

…n exception.

This information is already available from caller and in the
StackTrace object. We should eliminate this in the message parameter
since otherwise it will get duplicated in the generated HTML and text
representation.
  • Loading branch information...
1 parent d6927ad commit 639d6b3a1c2ba682dbe473e824dbbfc2393530f0 @miyagawa miyagawa committed Jan 25, 2011
Showing with 16 additions and 2 deletions.
  1. +15 −1 lib/Plack/Middleware/StackTrace.pm
  2. +1 −1 t/Plack-Middleware/stacktrace.t
@@ -19,7 +19,10 @@ sub call {
my $trace;
local $SIG{__DIE__} = sub {
- $trace = $StackTraceClass->new(indent => 1, message => $_[0], ignore_package => __PACKAGE__);
+ $trace = $StackTraceClass->new(
+ indent => 1, message => munge_error($_[0], [ caller ]),
+ ignore_package => __PACKAGE__,
+ );
die @_;
};
@@ -47,6 +50,17 @@ sub call {
return $res;
}
+sub munge_error {
+ my($err, $caller) = @_;
+ return $err if ref $err;
+
+ # Ugly hack to remove " at ... line ..." automatically appended by perl
+ # If there's a proper way to do this, please let me know.
+ $err =~ s/ at \Q$caller->[1]\E line $caller->[2]\.\n$//;
+
+ return $err;
+}
+
sub utf8_safe {
my $str = shift;
@@ -22,7 +22,7 @@ test_psgi $app, sub {
ok $res->is_error;
is_deeply [ $res->content_type ], [ 'text/html', 'charset=utf-8' ];
- like $res->content, qr/orz/;
+ like $res->content, qr/<title>Error: orz/;
};
done_testing;

0 comments on commit 639d6b3

Please sign in to comment.