Subject: | Log::Report::try truncates multi-line die messages |
Date: | Wed, 7 Jan 2015 18:34:36 -0800 |
To: | bug-Log-Report [...] rt.cpan.org |
From: | Ken Neighbors <ken [...] nsds.com> |
When using "Log::Report::try" around some code which calls "die" with
multiple lines (such as die Data::Dumper->Dump(...)), the internal effect
of die_decode truncates all but the first line of the error message. I
have patched Log/Report/Die.pm to keep all the lines in the message so that
"die" acts more like "Log::Report::error" which reports all the lines.
Here is a test case:
#!/usr/bin/perl -w
use Log::Report;
Log::Report::try {
die "This is the first of two lines.\nThis is the second line.\n";
Log::Report::error( "This is the first of two lines.\nThis is the
second line." );
};
$@->reportFatal;
You will find that the second line is omitted. If you comment out the
"die" line you will see that Log::Report::error keeps both lines intact.
Here is a patch of Log/Report/Die.pm:
--- Die.pm.orig 2015-01-08 02:24:21.789115374 +0000
+++ Die.pm.new 2015-01-08 02:24:21.789115374 +0000
@@ -37,13 +37,17 @@
$text[0] =~ s/\s*[.:;]?\s*$err\s*$// # the $err is translation
sensitive
or delete $opt{errno};
- my $msg = shift @text;
- length $msg or $msg = 'stopped';
+ my @msg = ( shift @text );
+ length $msg[0] or $msg[0] = 'stopped';
my @stack;
foreach (@text)
- { push @stack, [ $1, $2, $3 ]
- if m/^\s*(.*?)\s+called at (.*?) line (\d+)\s*$/;
+ { if(m/^\s*(.*?)\s+called at (.*?) line (\d+)\s*$/ )
+ { push @stack, [ $1, $2, $3 ];
+ }
+ else
+ { push @msg, $_;
+ }
}
$opt{stack} = \@stack;
$opt{classes} = [ 'perl', (@stack ? 'confess' : 'die') ];
@@ -52,7 +56,7 @@
= @{$opt{stack}} ? ($opt{errno} ? 'ALERT' : 'PANIC')
: ($opt{errno} ? 'FAULT' : 'ERROR');
- ($dietxt, \%opt, $reason, $msg);
+ ($dietxt, \%opt, $reason, join("\n",@msg));
}
"to die or not to die, that's the question";
Basically my change is to keep all lines which are not stack-trace lines in
the @msg array and join them back together at the end.
Ken
Message body is not shown because sender requested not to inline it.
Message body is not shown because sender requested not to inline it.