Skip to content

Commit

Permalink
Improve VCC error messages.
Browse files Browse the repository at this point in the history
Fixes: 	#2696
  • Loading branch information
bsdphk authored and Dridi committed Oct 16, 2018
1 parent deeca0f commit 2cf6e80
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
4 changes: 2 additions & 2 deletions bin/varnishtest/tests/v00018.vtc
Expand Up @@ -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); }
}
Expand All @@ -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 ; }
}
Expand Down
2 changes: 1 addition & 1 deletion bin/varnishtest/tests/v00020.vtc
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions bin/varnishtest/tests/v00021.vtc
Expand Up @@ -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; }
Expand Down
18 changes: 12 additions & 6 deletions lib/libvcc/vcc_parse.c
Expand Up @@ -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",
Expand All @@ -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");
}
Expand Down

0 comments on commit 2cf6e80

Please sign in to comment.