summaryrefslogtreecommitdiff
path: root/pp_ctl.c
diff options
context:
space:
mode:
authorYves Orton <demerphq@gmail.com>2022-11-25 19:35:38 +0100
committerYves Orton <demerphq@gmail.com>2022-12-09 18:34:58 +0100
commitc8b0222fe78d83d2c40d2141c264d0c1581429df (patch)
tree17144078846a52c4f0ac311d7831666a0b2f4847 /pp_ctl.c
parentd7d35ebd7f7c7f228d88b7b4b88b9a74b4fc5bf9 (diff)
downloadperl-c8b0222fe78d83d2c40d2141c264d0c1581429df.tar.gz
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.
Diffstat (limited to 'pp_ctl.c')
-rw-r--r--pp_ctl.c35
1 files changed, 31 insertions, 4 deletions
diff --git a/pp_ctl.c b/pp_ctl.c
index 1b0be6f196..68ee99bd4a 100644
--- a/pp_ctl.c
+++ b/pp_ctl.c
@@ -4307,10 +4307,13 @@ S_require_file(pTHX_ SV *sv)
sv_setsv_nomg(l, loader);
loader = l;
}
- if (sv_isobject(loader))
- count = call_method("INC", G_LIST);
- else
- count = call_sv(loader, G_LIST);
+ const char *method = NULL;
+ if (sv_isobject(loader)) {
+ method = "INC";
+ count = call_method(method, G_LIST|G_EVAL);
+ } else {
+ count = call_sv(loader, G_LIST|G_EVAL);
+ }
SPAGAIN;
if (count > 0) {
@@ -4367,6 +4370,30 @@ S_require_file(pTHX_ SV *sv)
PERL_SCRIPT_MODE);
}
SP--;
+ } else {
+ SV *errsv= ERRSV;
+ if (SvTRUE(errsv) && !SvROK(errsv)) {
+ STRLEN l;
+ char *pv= SvPV(errsv,l);
+ /* Heuristic to tell if this error message
+ * includes the standard line number info:
+ * check if the line ends in digit dot newline.
+ * If it does then we add some extra info so
+ * its obvious this is coming from a hook.
+ * If it is a user generated error we try to
+ * leave it alone. l>12 is to ensure the
+ * other checks are in string, but also
+ * accounts for "at ... line 1.\n" to a
+ * certain extent. Really we should check
+ * further, but this is good enough for back
+ * compat I think.
+ */
+ if (l>=12 && pv[l-1] == '\n' && pv[l-2] == '.' && isDIGIT(pv[l-3]))
+ sv_catpvf(errsv, "%s %s hook died--halting @INC search",
+ method ? method : "INC",
+ method ? "method" : "sub");
+ croak_sv(errsv);
+ }
}
/* FREETMPS may free our filter_cache */