Skip to content

Commit 3cf01b3

Browse files
demerphqkhwilliamson
authored andcommitted
error messages - do not repeat class names twice in our error messages
Showing the classname twice in the error message seems friendly when the class name is short, but when it is long enough that the line wraps the duplication just increases cognitive load understand the error message. This is especially the case when the value is a total error and contains gibberish or a long binary string or such things, something that is all to common with this type of error. Even with the recently merged eliding of names the duplication means that an error message can be 2k long in the worst case, mostly because of the unnecessary duplication. As a compromise we can simply replace the second invocation of the class name by saying "it" instead, and that is what this patch does. The error message is still friendly, but not repetitive. We could also use "the package" if people preferred. Thus: $ perl -le'("x" x 50)->new()' Can't locate object method "new" via package "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" (perhaps you forgot to load "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"?) at -e line 1. Turns into: $ ./perl -le'("x" x 50)->new()' Can't locate object method "new" via package "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" (perhaps you forgot to load it?) at -e line 1.
1 parent 00f06a3 commit 3cf01b3

File tree

6 files changed

+12
-14
lines changed

6 files changed

+12
-14
lines changed

gv.c

+4-5
Original file line numberDiff line numberDiff line change
@@ -961,12 +961,11 @@ S_gv_fetchmeth_internal(pTHX_ HV* stash, SV* meth, const char* name, STRLEN len,
961961
Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX),
962962
"While trying to resolve method call %.*s->%.*s()"
963963
" can not locate package %" SVf_QUOTEDPREFIX " yet it is mentioned in @%.*s::ISA"
964-
" (perhaps you forgot to load %" SVf_QUOTEDPREFIX "?)",
964+
" (perhaps you forgot to load it?)",
965965
(int) hvnamelen, hvname,
966966
(int) len, name,
967967
SVfARG(linear_sv),
968-
(int) hvnamelen, hvname,
969-
SVfARG(linear_sv));
968+
(int) hvnamelen, hvname);
970969
}
971970
}
972971
continue;
@@ -1265,9 +1264,9 @@ Perl_gv_fetchmethod_pvn_flags(pTHX_ HV *stash, const char *name, const STRLEN le
12651264
Perl_croak(aTHX_
12661265
"Can't locate object method %" UTF8f_QUOTEDPREFIX ""
12671266
" via package %" SVf_QUOTEDPREFIX ""
1268-
" (perhaps you forgot to load %" SVf_QUOTEDPREFIX "?)",
1267+
" (perhaps you forgot to load it?)",
12691268
UTF8fARG(is_utf8, name_end - name, name),
1270-
SVfARG(packnamesv), SVfARG(packnamesv));
1269+
SVfARG(packnamesv));
12711270
}
12721271
}
12731272
}

pod/perldiag.pod

+2-3
Original file line numberDiff line numberDiff line change
@@ -1279,8 +1279,7 @@ unable to locate this library. See L<DynaLoader>.
12791279
functioning as a class, but that package doesn't define that particular
12801280
method, nor does any of its base classes. See L<perlobj>.
12811281

1282-
=item Can't locate object method "%s" via package "%s" (perhaps you forgot
1283-
to load "%s"?)
1282+
=item Can't locate object method "%s" via package "%s" (perhaps you forgot to load it?)
12841283

12851284
(F) You called a method on a class that did not exist, and the method
12861285
could not be found in UNIVERSAL. This often means that a method
@@ -8213,7 +8212,7 @@ can be determined from the template alone. This is not possible if
82138212
it contains any of the codes @, /, U, u, w or a *-length. Redesign
82148213
the template.
82158214

8216-
=item While trying to resolve method call %s->%s() can not locate package "%s" yet it is mentioned in @%s::ISA (perhaps you forgot to load "%s"?)
8215+
=item While trying to resolve method call %s->%s() can not locate package "%s" yet it is mentioned in @%s::ISA (perhaps you forgot to load it?)
82178216

82188217
(W syntax) It is possible that the C<@ISA> contains a misspelled or never loaded
82198218
package name, which can result in perl choosing an unexpected parent

pp_sys.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1169,8 +1169,8 @@ PP_wrapped(pp_tie, 0, 1)
11691169
: newSVpvs_flags("main", SVs_TEMP);
11701170
DIE(aTHX_ "Can't locate object method %" PVf_QUOTEDPREFIX
11711171
" via package %" SVf_QUOTEDPREFIX
1172-
" (perhaps you forgot to load %" SVf_QUOTEDPREFIX "?)",
1173-
methname, SVfARG(stashname), SVfARG(stashname));
1172+
" (perhaps you forgot to load it?)",
1173+
methname, SVfARG(stashname));
11741174
}
11751175
}
11761176
else if (!(gv = gv_fetchmethod(stash, methname))) {

t/lib/warnings/gv

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Undefined subroutine &main::joe called at - line 3.
2828
use warnings 'syntax' ;
2929
@ISA = qw(Fred); __PACKAGE__->joe()
3030
EXPECT
31-
While trying to resolve method call main->joe() can not locate package "Fred" yet it is mentioned in @main::ISA (perhaps you forgot to load "Fred"?) at - line 3.
31+
While trying to resolve method call main->joe() can not locate package "Fred" yet it is mentioned in @main::ISA (perhaps you forgot to load it?) at - line 3.
3232
Can't locate object method "joe" via package "main" at - line 3.
3333
########
3434
# gv.c
@@ -57,7 +57,7 @@ $a = bless [], 'C';
5757
$a->foo();
5858
__END__
5959
EXPECT
60-
While trying to resolve method call C->foo() can not locate package "A" yet it is mentioned in @C::ISA (perhaps you forgot to load "A"?) at - line 18.
60+
While trying to resolve method call C->foo() can not locate package "A" yet it is mentioned in @C::ISA (perhaps you forgot to load it?) at - line 18.
6161
I'm in B's foo
6262
########
6363
# gv.c

t/op/tie.t

+1-1
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,7 @@ sub IO::File::TIEARRAY {
930930
}
931931
fileno FOO; tie @a, "FOO"
932932
EXPECT
933-
Can't locate object method "TIEARRAY" via package "FOO" (perhaps you forgot to load "FOO"?) at - line 5.
933+
Can't locate object method "TIEARRAY" via package "FOO" (perhaps you forgot to load it?) at - line 5.
934934
########
935935
# tie into empty package name
936936
tie $foo, "";

t/run/fresh_perl.t

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ $array[128]=1
8181
########
8282
$x=0x0eabcd; print $x->ref;
8383
EXPECT
84-
Can't locate object method "ref" via package "961485" (perhaps you forgot to load "961485"?) at - line 1.
84+
Can't locate object method "ref" via package "961485" (perhaps you forgot to load it?) at - line 1.
8585
########
8686
chop ($str .= <DATA>);
8787
########

0 commit comments

Comments
 (0)