[6.0] 2cf6e8023 Improve VCC error messages.

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Wed Oct 31 13:08:06 UTC 2018


commit 2cf6e8023ecfb626e1fc336fef5a72a6d430b163
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Wed Aug 22 08:50:12 2018 +0000

    Improve VCC error messages.
    
    Fixes:  #2696

diff --git a/bin/varnishtest/tests/v00018.vtc b/bin/varnishtest/tests/v00018.vtc
index bc152ec01..d0a21eb1d 100644
--- a/bin/varnishtest/tests/v00018.vtc
+++ b/bin/varnishtest/tests/v00018.vtc
@@ -83,7 +83,7 @@ varnish v1 -errvcl {Unknown token '<<' when looking for STRING} {
 	sub vcl_recv { ban (<<); }
 }
 
-varnish v1 -errvcl {Expected an action, 'if', '{' or '}'} {
+varnish v1 -errvcl {Symbol not found} {
 	backend b { .host = "127.0.0.1"; }
 	sub vcl_recv { ban_hash (if); }
 }
@@ -93,7 +93,7 @@ varnish v1 -vcl {
 	sub vcl_recv { ban ("req.url ~ foo"); }
 }
 
-varnish v1 -errvcl {Expected an action, 'if', '{' or '}'} {
+varnish v1 -errvcl "Symbol not found" {
 	backend b { .host = "127.0.0.1"; }
 	sub vcl_recv { kluf ; }
 }
diff --git a/bin/varnishtest/tests/v00020.vtc b/bin/varnishtest/tests/v00020.vtc
index 4bebb20ae..9b0578522 100644
--- a/bin/varnishtest/tests/v00020.vtc
+++ b/bin/varnishtest/tests/v00020.vtc
@@ -20,7 +20,7 @@ varnish v1 -errvcl {Found: '0' at} { 0; }
 # VCLs tokenstream.
 # XXX: A better error message would be desirable
 
-varnish v1 -errvcl {Expected an action, 'if', } " sub vcl_recv { { } { "
+varnish v1 -errvcl {Symbol not found} " sub vcl_recv { { } { "
 
 varnish v1 -errvcl {Comparison of different types: INT '!=' STRING} {
 	sub vcl_recv {
diff --git a/bin/varnishtest/tests/v00021.vtc b/bin/varnishtest/tests/v00021.vtc
index 871f8732d..689b3faea 100644
--- a/bin/varnishtest/tests/v00021.vtc
+++ b/bin/varnishtest/tests/v00021.vtc
@@ -12,13 +12,13 @@ varnish v1 -errvcl {Variable is read only.} {
 	sub vcl_recv { call foo ; }
 }
 
-varnish v1 -errvcl "Expected an action, 'if', '{' or '}'" {
+varnish v1 -errvcl "Symbol not found" {
 	backend b { .host = "127.0.0.1"; }
 
 	sub vcl_recv { discard; }
 }
 
-varnish v1 -errvcl "Expected an action, 'if', '{' or '}'" {
+varnish v1 -errvcl "Symbol not found" {
 	backend b { .host = "127.0.0.1"; }
 
 	sub foo { discard; }
diff --git a/lib/libvcc/vcc_parse.c b/lib/libvcc/vcc_parse.c
index a4bbf1182..cc0c34751 100644
--- a/lib/libvcc/vcc_parse.c
+++ b/lib/libvcc/vcc_parse.c
@@ -160,7 +160,7 @@ vcc_Compound(struct vcc *tl)
 			vcc_NextToken(tl);
 			tl->indent -= INDENT;
 			Fb(tl, 1, "}\n");
-			return;
+			break;
 		case CSRC:
 			if (tl->allow_inline_c) {
 				Fb(tl, 1, "%.*s\n",
@@ -177,25 +177,31 @@ vcc_Compound(struct vcc *tl)
 			VSB_printf(tl->sb,
 			    "End of input while in compound statement\n");
 			tl->err = 1;
-			return;
+			break;
 		case ID:
 			sym = VCC_SymbolGet(tl, SYM_NONE, SYMTAB_NOERR,
 			    XREF_NONE);
-			if (sym != NULL && sym->action != NULL) {
+			if (sym == NULL) {
+				VSB_printf(tl->sb, "Symbol not found.\n");
+				vcc_ErrWhere(tl, tl->t);
+			} else if (sym->action == NULL) {
+				VSB_printf(tl->sb,
+				    "Symbol cannot be used here.\n");
+				vcc_ErrWhere(tl, tl->t);
+			} else {
 				if (sym->action_mask != 0)
 					vcc_AddUses(tl, t, NULL,
 					    sym->action_mask,
 					    "Not a valid action");
 				sym->action(tl, t, sym);
-				break;
 			}
-			/* FALLTHROUGH */
+			break;
 		default:
 			/* We deliberately do not mention inline C */
 			VSB_printf(tl->sb,
 			    "Expected an action, 'if', '{' or '}'\n");
 			vcc_ErrWhere(tl, tl->t);
-			return;
+			break;
 		}
 		Fb(tl, 1, "if (*ctx->handling) return;\n");
 	}


More information about the varnish-commit mailing list