summaryrefslogtreecommitdiff
path: root/lib/diagnostics.pm
diff options
context:
space:
mode:
authorFather Chrysostomos <sprout@cpan.org>2011-12-26 16:55:35 -0800
committerFather Chrysostomos <sprout@cpan.org>2011-12-26 16:55:35 -0800
commit2dde04676ae62e4ba4bd87d6749bae66d1bed890 (patch)
treec63ccc104bf42d9bd29da47355effe79e61627a1 /lib/diagnostics.pm
parentf8c3fed4ccf90f2b41f9acc87c1b11359f095598 (diff)
downloadperl-2dde04676ae62e4ba4bd87d6749bae66d1bed890.tar.gz
Fix diagnostic.pm’s backtraces
Currently a user-defined error message is printed out like this: ----- Uncaught exception from user code: panick: at -e line 1. at -e line 1 main::baz() called at -e line 1 main::bar() called at -e line 1 main::foo() called at -e line 1 ----- Errors generated from perl itself are printed like this: ----- panic: at -e line 1 (#1) (P) An internal error. Uncaught exception from user code: panic: at -e line 1. at -e line 1 main::baz() called at -e line 1 main::bar() called at -e line 1 main::foo() called at -e line 1 ----- By using Carp::confess(), we end up with a screwy backtrace. Some- times it just ends up repeating the error and line number: ----- panic: at -e line 1 (#1) (P) An internal error. Uncaught exception from user code: panic: at -e line 1. at -e line 1 ----- Uncaught exception from user code: panick at -e line 1. at -e line 1 ----- This commit cleans these up to print like this: ----- Uncaught exception from user code: panick: at -e line 1. main::baz() called at -e line 1 main::bar() called at -e line 1 main::foo() called at -e line 1 ----- panic: at -e line 1 (#1) (P) An internal error. Uncaught exception from user code: panic: at -e line 1. main::baz() called at -e line 1 main::bar() called at -e line 1 main::foo() called at -e line 1 ----- panic: at -e line 1 (#1) (P) An internal error. Uncaught exception from user code: panic: at -e line 1. ----- Uncaught exception from user code: panick at -e line 1. ----- You might ask: Why not remove the ‘uncaught exception’ message alto- gether after an error description. It’s because the error description is a diagnostic, which only prints once for each error or warning encountered. So you could have eval { die } somewhere else in the code, which causes a description to be printed. And later you have a die() that exits the program, but nothing gets printed. In other words, the description of the message does not replace the error.
Diffstat (limited to 'lib/diagnostics.pm')
-rw-r--r--lib/diagnostics.pm5
1 files changed, 4 insertions, 1 deletions
diff --git a/lib/diagnostics.pm b/lib/diagnostics.pm
index dc1a9b0f39..6c166a3b93 100644
--- a/lib/diagnostics.pm
+++ b/lib/diagnostics.pm
@@ -576,7 +576,10 @@ sub death_trap {
# Have carp skip over death_trap() when showing the stack trace.
local($Carp::CarpLevel) = 1;
- confess "Uncaught exception from user code:\n\t$exception";
+ die Carp::longmess("__diagnostics__")
+ =~ s/^__diagnostics__.*?line \d+\.?\n/
+ "Uncaught exception from user code:\n\t$exception"
+ /re;
# up we go; where we stop, nobody knows, but i think we die now
# but i'm deeply afraid of the &$olddie guy reraising and us getting
# into an indirect recursion loop