[master] db0baa744 Improve the VCL recursive sub calls error message

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Wed Dec 18 08:35:07 UTC 2019


commit db0baa744db9b71f5f14fba4b2e3b0c2e9d5a807
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date:   Wed Dec 18 08:49:45 2019 +0100

    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.

diff --git a/bin/varnishtest/tests/v00020.vtc b/bin/varnishtest/tests/v00020.vtc
index 06efb9021..b59fb5350 100644
--- a/bin/varnishtest/tests/v00020.vtc
+++ b/bin/varnishtest/tests/v00020.vtc
@@ -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 '.'} {
diff --git a/bin/varnishtest/tests/v00021.vtc b/bin/varnishtest/tests/v00021.vtc
index fe34b6f14..0ae6dc5a3 100644
--- a/bin/varnishtest/tests/v00021.vtc
+++ b/bin/varnishtest/tests/v00021.vtc
@@ -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; }
diff --git a/lib/libvcc/vcc_action.c b/lib/libvcc/vcc_action.c
index 95d3a9216..a1b57b407 100644
--- a/lib/libvcc/vcc_action.c
+++ b/lib/libvcc/vcc_action.c
@@ -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, ';');
diff --git a/lib/libvcc/vcc_compile.h b/lib/libvcc/vcc_compile.h
index 9e1875c8b..c356e0788 100644
--- a/lib/libvcc/vcc_compile.h
+++ b/lib/libvcc/vcc_compile.h
@@ -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 *,
diff --git a/lib/libvcc/vcc_xref.c b/lib/libvcc/vcc_xref.c
index 342fdb967..e680c1ba1 100644
--- a/lib/libvcc/vcc_xref.c
+++ b/lib/libvcc/vcc_xref.c
@@ -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);
 		}


More information about the varnish-commit mailing list