Subject: | BEGIN{ try{ error "foo" } } exits without a message |
Calling Log::Report::error within a try{} within a BEGIN {} block results in the application terminating without any message nor a nonzero exit code rather than returning from the try{} block as per the documentation.
Reproduce:
perl -MLog::Report -e 'BEGIN { try { error "no-show" }; print "done: $@" }'
Output: (none)
Expected output:
done: try-block stopped with ERROR: error: no-show
Details:
After some debugging I have determined what code is actually executed in Log::Report:
* line 116, $reporter->{filters} is empty;
* line 133, @$disp contains a Log::Report::Dispatcher::Try, which then causes:
* line 136, $d->log(...) to be called, which merely pushes an exception that is ignored (even with the patch);
* line 140, @last_call is empty;
* line 145, $stop is true;
* line 147 is executed (an exit()), as $^S is undefined.
The documentation for $^S states that an undefined value does NOT indicate whether exceptions are being caught (see http://perldoc.perl.org/perlvar.html#%24^S).
Proposed change:
--- lib/Log/Report.pm (original)
+++ lib/Log/Report.pm (patched)
@@ -144,7 +144,7 @@
if($stop)
{ # ^S = EXCEPTIONS_BEING_CAUGHT, within eval or try
- $^S or exit($opts->{errno} || 0);
+ (defined($^S) ? $^S : 1) or exit($opts->{errno} || 0);
$! = $opts->{errno} || 0;
$@ = $exception || Log::Report::Exception->new(report_opts => $opts