Commit db0baa74 authored by Dridi Boukelmoune's avatar Dridi Boukelmoune

Improve the VCL recursive sub calls error message

Before:

    ...called from "foo"
    ('<vcl.inline>' Line 5 Pos 27)
            sub bar { call foo; }
    --------------------------#--

After:

    ...called from "bar"
    ('<vcl.inline>' Line 5 Pos 24)
            sub bar { call foo; }
    -----------------------###---

This fixes the "called from" part of the message to refer to the caller
instead of the callee, and underlines the symbol token instead of the
semi-colon.
parent 6a394677
......@@ -246,14 +246,57 @@ varnish v1 -errvcl {Not available in method 'vcl_recv'.} {
}
}
varnish v1 -errvcl {Not available from method 'vcl_recv'.} {
varnish v1 -errvcl {
('<vcl.inline>' Line 4 Pos 44) -- (Pos 49)
sub foo { set req.http.foo = 100 + beresp.status; }
-------------------------------------------######----------
Not available from method 'vcl_recv'.
...in subroutine "foo"
('<vcl.inline>' Line 4 Pos 13)
sub foo { set req.http.foo = 100 + beresp.status; }
------------###--------------------------------------------
...called from "vcl_recv"
('<vcl.inline>' Line 5 Pos 29)
sub vcl_recv { call foo; }
----------------------------###---
} {
backend b { .host = "127.0.0.1"; }
sub foo {
set req.http.foo = 100 + beresp.status;
}
sub vcl_recv {
call foo;
}
sub foo { set req.http.foo = 100 + beresp.status; }
sub vcl_recv { call foo; }
}
varnish v1 -errvcl {
('<vcl.inline>' Line 4 Pos 44) -- (Pos 49)
sub foo { set req.http.foo = 100 + beresp.status; }
-------------------------------------------######----------
Not available from method 'vcl_recv'.
...in subroutine "foo"
('<vcl.inline>' Line 4 Pos 13)
sub foo { set req.http.foo = 100 + beresp.status; }
------------###--------------------------------------------
...called from "bar"
('<vcl.inline>' Line 5 Pos 24)
sub bar { call foo; }
-----------------------###---
...called from "vcl_recv"
('<vcl.inline>' Line 6 Pos 29)
sub vcl_recv { call bar; }
----------------------------###---
} {
backend b { .host = "127.0.0.1"; }
sub foo { set req.http.foo = 100 + beresp.status; }
sub bar { call foo; }
sub vcl_recv { call bar; }
}
varnish v1 -errvcl {Name of ACL, 'foo.bar', contains illegal character '.'} {
......
......@@ -25,14 +25,54 @@ varnish v1 -errvcl "Symbol not found" {
sub vcl_recv { call foo; }
}
varnish v1 -errvcl "Function recurses on" {
varnish v1 -errvcl {
Function recurses on
('<vcl.inline>' Line 5 Pos 13)
sub foo { call foo; }
------------###--------------
...called from "foo"
('<vcl.inline>' Line 5 Pos 24)
sub foo { call foo; }
-----------------------###---
...called from "vcl_recv"
('<vcl.inline>' Line 6 Pos 29)
sub vcl_recv { call foo; }
----------------------------###---
} {
backend b { .host = "127.0.0.1"; }
sub foo { call foo; }
sub vcl_recv { call foo; }
}
varnish v1 -errvcl "Function recurses on" {
varnish v1 -errvcl {
Function recurses on
('<vcl.inline>' Line 6 Pos 13)
sub foo { call bar; }
------------###--------------
...called from "bar"
('<vcl.inline>' Line 5 Pos 24)
sub bar { call foo; }
-----------------------###---
...called from "foo"
('<vcl.inline>' Line 6 Pos 24)
sub foo { call bar; }
-----------------------###---
...called from "vcl_recv"
('<vcl.inline>' Line 7 Pos 29)
sub vcl_recv { call foo; }
----------------------------###---
} {
backend b { .host = "127.0.0.1"; }
sub bar { call foo; }
......
......@@ -42,12 +42,14 @@
static void v_matchproto_(sym_act_f)
vcc_act_call(struct vcc *tl, struct token *t, struct symbol *sym)
{
struct token *t0;
(void)t;
ExpectErr(tl, ID);
t0 = tl->t;
sym = VCC_SymbolGet(tl, SYM_SUB, SYMTAB_CREATE, XREF_REF);
if (sym != NULL) {
vcc_AddCall(tl, sym);
vcc_AddCall(tl, t0, sym);
VCC_GlobalSymbol(sym, SUB, "VGC_function");
Fb(tl, 1, "%s(ctx);\n", sym->rname);
SkipToken(tl, ';');
......
......@@ -400,7 +400,7 @@ sym_act_f vcc_Act_New;
int vcc_CheckReferences(struct vcc *tl);
void VCC_XrefTable(struct vcc *);
void vcc_AddCall(struct vcc *, struct symbol *);
void vcc_AddCall(struct vcc *, struct token *, struct symbol *);
void vcc_ProcAction(struct proc *p, unsigned action, struct token *t);
int vcc_CheckAction(struct vcc *tl);
void vcc_AddUses(struct vcc *, const struct token *, const struct token *,
......
......@@ -108,7 +108,7 @@ vcc_AddUses(struct vcc *tl, const struct token *t1, const struct token *t2,
AN(tl->curproc);
pu = TlAlloc(tl, sizeof *pu);
assert(pu != NULL);
AN(pu);
pu->t1 = t1;
pu->t2 = t2;
if (pu->t2 == NULL)
......@@ -120,15 +120,15 @@ vcc_AddUses(struct vcc *tl, const struct token *t1, const struct token *t2,
}
void
vcc_AddCall(struct vcc *tl, struct symbol *sym)
vcc_AddCall(struct vcc *tl, struct token *t, struct symbol *sym)
{
struct proccall *pc;
AN(sym);
pc = TlAlloc(tl, sizeof *pc);
assert(pc != NULL);
AN(pc);
pc->sym = sym;
pc->t = tl->t;
pc->t = t;
pc->fm = tl->curproc;
VTAILQ_INSERT_TAIL(&tl->curproc->calls, pc, list);
}
......@@ -180,8 +180,8 @@ vcc_CheckActionRecurse(struct vcc *tl, struct proc *p, unsigned bitmap)
return (1);
}
if (vcc_CheckActionRecurse(tl, pc->sym->proc, bitmap)) {
VSB_printf(tl->sb, "\n...called from \"%s\"\n",
pc->sym->name);
VSB_printf(tl->sb, "\n...called from \"%.*s\"\n",
PF(p->name));
vcc_ErrWhere(tl, pc->t);
return (1);
}
......@@ -259,7 +259,7 @@ vcc_CheckUseRecurse(struct vcc *tl, const struct proc *p,
VTAILQ_FOREACH(pc, &p->calls, list) {
if (vcc_CheckUseRecurse(tl, pc->sym->proc, m)) {
VSB_printf(tl->sb, "\n...called from \"%.*s\"\n",
PF(pc->fm->name));
PF(p->name));
vcc_ErrWhere(tl, pc->t);
return (1);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment