diff options
author | Yves Orton <demerphq@gmail.com> | 2022-08-01 16:21:12 +0200 |
---|---|---|
committer | Yves Orton <demerphq@gmail.com> | 2022-08-25 14:46:33 +0200 |
commit | 33ef5d2cdf69f4a7b22ff4c220758689b59b28a8 (patch) | |
tree | 82f059df72c6aac72eff8ff761051f69debba20e /pp_sys.c | |
parent | 697eaf802a042beb1c1c6f1983a08a147f12eb72 (diff) | |
download | perl-33ef5d2cdf69f4a7b22ff4c220758689b59b28a8.tar.gz |
sv.c - add a _QUOTEDPREFIX version of SVf, UTF8f, and HEKf for use in error messages.
These new formats are intended to be used in error messages where
we want to show the contents of a string without any possible
hidden characters not rendering in the error message, and where
it would be unreasonable to show every character of the string
if it is very long.
A good example would be when we want to say that a class name is
illegal. Consider:
"Foo\0"->thing()
should not throw an error message about "Foo" being missing, the fact
there is a null in there should be visible to the developer.
Similarly if we had
("x" x 1000_000)->thing()
we also do not want to throw a 1MB error message as it is generally
just unhelpful, a class name that long is almost certainly a mistake.
Currently this patch restricts it to showing 256 characters, the first
128 followed by an ellipses followed by the last 128 characters, but the
docs are such that we can change that if we wish, I suspect something
like 100 would be more reasonable. You can override the define
PERL_QUOTEDPREFIX_LEN to a longer value in Configure if you wish.
Example usage:
other= newSVpvs("Some\0::Thing\n");
sv_catpvf(msg_sv,"%" SVf_QUOTEDPREFIX, SVfARG(other));
Should append
"Some\0::Thing\n"
to the msg_sv. If it were very long it would have ellipses infixed. The
class name "x" x 1_000_000 would show
Can't locate object method "non_existent_method" via \
package "x[repeated 128 times]"..."x[repeated 128 times]" \
(perhaps you forgot to load \
"x[repeated 128 times]"..."x[repeated 128 times]"?) at -e line 1.
(but obviously as one line with the literal text of the class instead of
"[repeated 128 times]")
This patch changes a variety of error messages that used to output the
full string always. I haven't changed every place that this could happen
yet, just the main ones related to method calls, subroutine names and
the like.
Diffstat (limited to 'pp_sys.c')
-rw-r--r-- | pp_sys.c | 14 |
1 files changed, 9 insertions, 5 deletions
@@ -932,7 +932,8 @@ PP(pp_tie) stash = gv_stashsv(*MARK, 0); if (!stash) { if (SvROK(*MARK)) - DIE(aTHX_ "Can't locate object method \"%s\" via package \"%" SVf "\"", + DIE(aTHX_ "Can't locate object method %" PVf_QUOTEDPREFIX + " via package %" SVf_QUOTEDPREFIX, methname, SVfARG(*MARK)); else if (isGV(*MARK)) { /* If the glob doesn't name an existing package, using @@ -940,15 +941,17 @@ PP(pp_tie) * generate the name for the error message explicitly. */ SV *stashname = sv_newmortal(); gv_fullname4(stashname, (GV *) *MARK, NULL, FALSE); - DIE(aTHX_ "Can't locate object method \"%s\" via package \"%" SVf "\"", + DIE(aTHX_ "Can't locate object method %" PVf_QUOTEDPREFIX + " via package %" SVf_QUOTEDPREFIX, methname, SVfARG(stashname)); } else { SV *stashname = !SvPOK(*MARK) ? &PL_sv_no : SvCUR(*MARK) ? *MARK : newSVpvs_flags("main", SVs_TEMP); - DIE(aTHX_ "Can't locate object method \"%s\" via package \"%" SVf "\"" - " (perhaps you forgot to load \"%" SVf "\"?)", + DIE(aTHX_ "Can't locate object method %" PVf_QUOTEDPREFIX + " via package %" SVf_QUOTEDPREFIX + " (perhaps you forgot to load %" SVf_QUOTEDPREFIX "?)", methname, SVfARG(stashname), SVfARG(stashname)); } } @@ -957,7 +960,8 @@ PP(pp_tie) * been deleted from the symbol table, which this one can't * be, since we just looked it up by name. */ - DIE(aTHX_ "Can't locate object method \"%s\" via package \"%" HEKf "\"", + DIE(aTHX_ "Can't locate object method %" PVf_QUOTEDPREFIX + " via package %" HEKf_QUOTEDPREFIX , methname, HvENAME_HEK_NN(stash)); } ENTER_with_name("call_TIE"); |