Skip to content

Commit 455b620

Browse files
committed
error messages - do not repeat class names twice in our error messages
Showing the classname twice in the error message just increases cognitive load understanding the message when the class/package name is more than a few components long, and can easily make what should be a simple one line error message wrap and be unreadable. We can simply replace the second invocation of the class name by saying "it" instead, and that is what this patch does. It is still friendly, but not repetitive. 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 39629dc commit 455b620

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
@@ -917,12 +917,11 @@ S_gv_fetchmeth_internal(pTHX_ HV* stash, SV* meth, const char* name, STRLEN len,
917917
Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX),
918918
"While trying to resolve method call %.*s->%.*s()"
919919
" can not locate package %" SVf_QUOTEDPREFIX " yet it is mentioned in @%.*s::ISA"
920-
" (perhaps you forgot to load %" SVf_QUOTEDPREFIX "?)",
920+
" (perhaps you forgot to load it?)",
921921
(int) hvnamelen, hvname,
922922
(int) len, name,
923923
SVfARG(linear_sv),
924-
(int) hvnamelen, hvname,
925-
SVfARG(linear_sv));
924+
(int) hvnamelen, hvname);
926925
}
927926
}
928927
continue;
@@ -1263,9 +1262,9 @@ Perl_gv_fetchmethod_pvn_flags(pTHX_ HV *stash, const char *name, const STRLEN le
12631262
Perl_croak(aTHX_
12641263
"Can't locate object method %" UTF8f_QUOTEDPREFIX ""
12651264
" via package %" SVf_QUOTEDPREFIX ""
1266-
" (perhaps you forgot to load %" SVf_QUOTEDPREFIX "?)",
1265+
" (perhaps you forgot to load it?)",
12671266
UTF8fARG(is_utf8, name_end - name, name),
1268-
SVfARG(packnamesv), SVfARG(packnamesv));
1267+
SVfARG(packnamesv));
12691268
}
12701269
}
12711270
}

pod/perldiag.pod

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

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

11751174
(F) You called a method on a class that did not exist, and the method
11761175
could not be found in UNIVERSAL. This often means that a method
@@ -7820,7 +7819,7 @@ can be determined from the template alone. This is not possible if
78207819
it contains any of the codes @, /, U, u, w or a *-length. Redesign
78217820
the template.
78227821

7823-
=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"?)
7822+
=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?)
78247823

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

pp_sys.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -951,8 +951,8 @@ PP(pp_tie)
951951
: newSVpvs_flags("main", SVs_TEMP);
952952
DIE(aTHX_ "Can't locate object method %" PVf_QUOTEDPREFIX
953953
" via package %" SVf_QUOTEDPREFIX
954-
" (perhaps you forgot to load %" SVf_QUOTEDPREFIX "?)",
955-
methname, SVfARG(stashname), SVfARG(stashname));
954+
" (perhaps you forgot to load it?)",
955+
methname, SVfARG(stashname));
956956
}
957957
}
958958
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)