Skip to content

Commit c8b0222

Browse files
committed
pp_ctl.c - eval INC hooks, and rethrow errors with more useful message
When an INC hook blows up debugging what is going on can be somewhat difficult. This adds some debugging data if the error message does not seem to be customized.
1 parent d7d35eb commit c8b0222

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

pp_ctl.c

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4307,10 +4307,13 @@ S_require_file(pTHX_ SV *sv)
43074307
sv_setsv_nomg(l, loader);
43084308
loader = l;
43094309
}
4310-
if (sv_isobject(loader))
4311-
count = call_method("INC", G_LIST);
4312-
else
4313-
count = call_sv(loader, G_LIST);
4310+
const char *method = NULL;
4311+
if (sv_isobject(loader)) {
4312+
method = "INC";
4313+
count = call_method(method, G_LIST|G_EVAL);
4314+
} else {
4315+
count = call_sv(loader, G_LIST|G_EVAL);
4316+
}
43144317
SPAGAIN;
43154318

43164319
if (count > 0) {
@@ -4367,6 +4370,30 @@ S_require_file(pTHX_ SV *sv)
43674370
PERL_SCRIPT_MODE);
43684371
}
43694372
SP--;
4373+
} else {
4374+
SV *errsv= ERRSV;
4375+
if (SvTRUE(errsv) && !SvROK(errsv)) {
4376+
STRLEN l;
4377+
char *pv= SvPV(errsv,l);
4378+
/* Heuristic to tell if this error message
4379+
* includes the standard line number info:
4380+
* check if the line ends in digit dot newline.
4381+
* If it does then we add some extra info so
4382+
* its obvious this is coming from a hook.
4383+
* If it is a user generated error we try to
4384+
* leave it alone. l>12 is to ensure the
4385+
* other checks are in string, but also
4386+
* accounts for "at ... line 1.\n" to a
4387+
* certain extent. Really we should check
4388+
* further, but this is good enough for back
4389+
* compat I think.
4390+
*/
4391+
if (l>=12 && pv[l-1] == '\n' && pv[l-2] == '.' && isDIGIT(pv[l-3]))
4392+
sv_catpvf(errsv, "%s %s hook died--halting @INC search",
4393+
method ? method : "INC",
4394+
method ? "method" : "sub");
4395+
croak_sv(errsv);
4396+
}
43704397
}
43714398

43724399
/* FREETMPS may free our filter_cache */

t/op/require_errors.t

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,6 @@ like $@, qr/^Can't locate \Q$nonsearch\E at/,
388388
{ }, 'Blessed subs that die produce expected extra message');
389389
}
390390
{
391-
local $::TODO = "Pending better error messages (eval)";
392391
# as of 5.37.7
393392
fresh_perl_like(
394393
'sub CB::INC { die "bad mojo" } '

0 commit comments

Comments
 (0)