Fix diagnostic.pm’s backtraces
authorFather Chrysostomos <sprout@cpan.org>
Tue, 27 Dec 2011 00:55:35 +0000 (16:55 -0800)
committerFather Chrysostomos <sprout@cpan.org>
Tue, 27 Dec 2011 00:55:35 +0000 (16:55 -0800)
commit2dde04676ae62e4ba4bd87d6749bae66d1bed890
treec63ccc104bf42d9bd29da47355effe79e61627a1
parentf8c3fed4ccf90f2b41f9acc87c1b11359f095598
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.
lib/diagnostics.pm
lib/diagnostics.t