Skip to content

Commit

Permalink
Improve error messages
Browse files Browse the repository at this point in the history
Commit 52749df added more information to error messages to aid
debugging, but most plugin follow-up questions are code references, not
method names, and they would result in an ugly CODE(0x...) in the error
message.

This change adds the fully qualified name of plugin methods. Not sure if
I like that, I might drop the RevBank::Plugin:: prefix at some point.
  • Loading branch information
Juerd committed May 9, 2024
1 parent 7f86037 commit 62d3e3a
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions revbank
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use experimental 'isa'; # stable since v5.36
use experimental 'signatures'; # stable since v5.36

use List::Util qw(uniq);
use Sub::Util qw(subname);
use POSIX qw(ttyname);

use FindBin qw($RealBin);
Expand Down Expand Up @@ -167,6 +168,11 @@ OUTER: for (;;) {
"unexpected trailing input (use ';' to separate transactions)."
);

my $coderef = ref($method) ? $method : $plugin->can($method);
my ($mname) = $coderef
? (subname($coderef) eq "__ANON__" ? "" : subname($coderef) . ": ")
: (ref($method) ? "" : "$method: ");

my ($rv, @rvargs) =

($word =~ /[^\x20-\x7f]/ and $method eq 'command' || !$plugin->AllChars($method))
Expand All @@ -183,11 +189,12 @@ OUTER: for (;;) {
$retry = $@->reason;
redo OUTER;
} elsif ($@) {
call_hooks "plugin_fail", $plugin->id, "$method: $@";
call_hooks "plugin_fail", $plugin->id, "$mname$@";
abort;
}

if (not defined $rv) {
call_hooks "plugin_fail", $plugin->id, "$method: No return code";
call_hooks "plugin_fail", $plugin->id, $mname . "No return code";
abort;
}
if (not ref $rv) {
Expand All @@ -204,8 +211,10 @@ OUTER: for (;;) {
$prompt = $rv;
@plugins = $plugin;
($method) = @rvargs;
call_hooks "plugin_fail", $plugin->id, "$method: No method supplied"
if not ref $method;
if (not ref $method) {
call_hooks "plugin_fail", $plugin->id, $mname . "No method supplied";
abort;
}

next WORD;
}
Expand Down Expand Up @@ -247,11 +256,11 @@ OUTER: for (;;) {
}
if ($rv == NEXT) {
next PLUGIN if $method eq 'command';
call_hooks "plugin_fail", $plugin->id, "$method: "
call_hooks "plugin_fail", $plugin->id, $mname
. "Only 'command' should ever return NEXT.";
abort;
}
call_hooks "plugin_fail", $plugin->id, "$method: Invalid return value";
call_hooks "plugin_fail", $plugin->id, $mname . "Invalid return value";
abort;
}
call_hooks "invalid_input", $cart, $origword, $word, \@allwords;
Expand Down

0 comments on commit 62d3e3a

Please sign in to comment.