[master] a80f4ef9a Unify bespoke error messages to "Symbol not found" before things get too confusing.
Poul-Henning Kamp
phk at FreeBSD.org
Mon Jun 3 07:23:11 UTC 2019
commit a80f4ef9a1763f78eea6acf106e03cb12bdf89b1
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Mon Jun 3 06:36:20 2019 +0000
Unify bespoke error messages to "Symbol not found" before things
get too confusing.
diff --git a/bin/varnishtest/tests/r01837.vtc b/bin/varnishtest/tests/r01837.vtc
index fbfd797c0..e96a44cf7 100644
--- a/bin/varnishtest/tests/r01837.vtc
+++ b/bin/varnishtest/tests/r01837.vtc
@@ -1,6 +1,6 @@
varnishtest "Test VCC errors out if probe is used before it is defined"
-varnish v1 -errvcl "Probe not found: 'p'" {
+varnish v1 -errvcl "Symbol not found: 'p'" {
backend b {
.host = "127.0.0.1";
.probe = p;
diff --git a/bin/varnishtest/tests/v00018.vtc b/bin/varnishtest/tests/v00018.vtc
index d0a21eb1d..fd519c981 100644
--- a/bin/varnishtest/tests/v00018.vtc
+++ b/bin/varnishtest/tests/v00018.vtc
@@ -133,7 +133,7 @@ varnish v1 -errvcl {Symbol 'vcl_recv' has wrong type (sub):} {
}
}
-varnish v1 -syntax 4.0 -errvcl {Not a VCL label:} {
+varnish v1 -syntax 4.0 -errvcl {Symbol not found:} {
sub vcl_recv {
return (vcl(vcl_recv));
}
diff --git a/bin/varnishtest/tests/v00019.vtc b/bin/varnishtest/tests/v00019.vtc
index f579b024a..d81455a15 100644
--- a/bin/varnishtest/tests/v00019.vtc
+++ b/bin/varnishtest/tests/v00019.vtc
@@ -64,7 +64,7 @@ varnish v1 -errvcl {Comparison of different types: STRING '==' INT} {
}
}
-varnish v1 -errvcl {Unknown variable: 'req.http.req.http.foo'} {
+varnish v1 -errvcl {Symbol not found: 'req.http.req.http.foo'} {
backend b { .host = "127.0.0.1"; }
sub vcl_recv {
set req.http.req.http.foo = "bar";
diff --git a/bin/varnishtest/tests/v00021.vtc b/bin/varnishtest/tests/v00021.vtc
index 44c4c0f3d..80ef0a93e 100644
--- a/bin/varnishtest/tests/v00021.vtc
+++ b/bin/varnishtest/tests/v00021.vtc
@@ -91,7 +91,7 @@ varnish v1 -vcl {
}
}
-varnish v1 -errvcl {Unknown variable: 'req.foobar'} {
+varnish v1 -errvcl {Symbol not found: 'req.foobar'} {
backend foo { .host = "127.0.0.1"; }
sub vcl_recv { set req.foobar = 3; }
}
diff --git a/lib/libvcc/vcc_action.c b/lib/libvcc/vcc_action.c
index 4e547a2ab..1e218cb4f 100644
--- a/lib/libvcc/vcc_action.c
+++ b/lib/libvcc/vcc_action.c
@@ -94,7 +94,7 @@ vcc_act_set(struct vcc *tl, struct token *t, struct symbol *sym)
(void)t;
ExpectErr(tl, ID);
t = tl->t;
- sym = VCC_SymbolGet(tl, SYM_VAR, "Unknown variable", XREF_NONE);
+ sym = VCC_SymbolGet(tl, SYM_VAR, SYMTAB_EXISTING, XREF_NONE);
ERRCHK(tl);
AN(sym);
if (sym->w_methods == 0) {
@@ -146,7 +146,7 @@ vcc_act_unset(struct vcc *tl, struct token *t, struct symbol *sym)
/* XXX: Wrong, should use VCC_Expr(HEADER) */
ExpectErr(tl, ID);
t = tl->t;
- sym = VCC_SymbolGet(tl, SYM_VAR, "Unknown variable", XREF_NONE);
+ sym = VCC_SymbolGet(tl, SYM_VAR, SYMTAB_EXISTING, XREF_NONE);
ERRCHK(tl);
AN(sym);
if (sym->u_methods == 0) {
@@ -269,7 +269,7 @@ vcc_act_return_vcl(struct vcc *tl)
ExpectErr(tl, '(');
vcc_NextToken(tl);
ExpectErr(tl, ID);
- sym = VCC_SymbolGet(tl, SYM_VCL, "Not a VCL label", XREF_NONE);
+ sym = VCC_SymbolGet(tl, SYM_VCL, SYMTAB_EXISTING, XREF_NONE);
ERRCHK(tl);
AN(sym);
if (sym->eval_priv == NULL) {
diff --git a/lib/libvcc/vcc_backend.c b/lib/libvcc/vcc_backend.c
index 4243b9da6..3200b1f84 100644
--- a/lib/libvcc/vcc_backend.c
+++ b/lib/libvcc/vcc_backend.c
@@ -432,7 +432,7 @@ vcc_ParseHostDef(struct vcc *tl, const struct token *t_be, const char *vgcname)
(void)vcc_default_probe(tl);
} else {
pb = VCC_SymbolGet(tl, SYM_PROBE,
- "Probe not found", XREF_REF);
+ SYMTAB_EXISTING, XREF_REF);
ERRCHK(tl);
AN(pb);
Fb(tl, 0, "\t.probe = %s,\n", pb->rname);
@@ -540,6 +540,7 @@ vcc_ParseBackend(struct vcc *tl)
} else {
sym = VCC_HandleSymbol(tl, BACKEND, "vgc_backend");
ERRCHK(tl);
+ AN(sym);
dn = sym->rname;
if (tl->default_director == NULL) {
tl->first_director = sym;
diff --git a/lib/libvcc/vcc_compile.h b/lib/libvcc/vcc_compile.h
index 3a2116a9f..4d0fb0574 100644
--- a/lib/libvcc/vcc_compile.h
+++ b/lib/libvcc/vcc_compile.h
@@ -350,13 +350,19 @@ void vcc_stevedore(struct vcc *vcc, const char *stv_name);
/* vcc_symb.c */
void VCC_PrintCName(struct vsb *vsb, const char *b, const char *e);
struct symbol *VCC_MkSym(struct vcc *tl, const char *b, vcc_kind_t, int, int);
-extern const char XREF_NONE[];
-extern const char XREF_DEF[];
-extern const char XREF_REF[];
-extern const char SYMTAB_NOERR[];
-extern const char SYMTAB_CREATE[];
-struct symbol *VCC_SymbolGet(struct vcc *, vcc_kind_t, const char *,
- const char *);
+
+struct symxref { const char *name; };
+extern const struct symxref XREF_NONE[1];
+extern const struct symxref XREF_DEF[1];
+extern const struct symxref XREF_REF[1];
+
+struct symmode { const char *name; };
+extern const struct symmode SYMTAB_NOERR[1];
+extern const struct symmode SYMTAB_CREATE[1];
+extern const struct symmode SYMTAB_EXISTING[1];
+
+struct symbol *VCC_SymbolGet(struct vcc *, vcc_kind_t,
+ const struct symmode *, const struct symxref *);
typedef void symwalk_f(struct vcc *tl, const struct symbol *s);
void VCC_WalkSymbols(struct vcc *tl, symwalk_f *func, vcc_kind_t);
diff --git a/lib/libvcc/vcc_expr.c b/lib/libvcc/vcc_expr.c
index dae6fe2f2..9c263e0b7 100644
--- a/lib/libvcc/vcc_expr.c
+++ b/lib/libvcc/vcc_expr.c
@@ -688,8 +688,7 @@ vcc_expr4(struct vcc *tl, struct expr **e, vcc_type_t fmt)
switch (tl->t->tok) {
case ID:
t = tl->t;
- sym = VCC_SymbolGet(tl, SYM_NONE, "Symbol not found",
- XREF_REF);
+ sym = VCC_SymbolGet(tl, SYM_NONE, SYMTAB_EXISTING, XREF_REF);
ERRCHK(tl);
AN(sym);
if (sym->kind == SYM_FUNC && sym->type == VOID) {
diff --git a/lib/libvcc/vcc_symb.c b/lib/libvcc/vcc_symb.c
index 9883dede4..18bfbe6b3 100644
--- a/lib/libvcc/vcc_symb.c
+++ b/lib/libvcc/vcc_symb.c
@@ -226,19 +226,25 @@ vcc_sym_in_tab(struct vcc *tl, struct symtab *st,
}
-const char XREF_NONE[] = "xref_none";
-const char XREF_DEF[] = "xref_def";
-const char XREF_REF[] = "xref_ref";
-const char SYMTAB_NOERR[] = "sym_noerror";
-const char SYMTAB_CREATE[] = "sym_create";
+const struct symxref XREF_NONE[1] = {{"xref_none"}};
+const struct symxref XREF_DEF[1] = {{"xref_def"}};
+const struct symxref XREF_REF[1] = {{"xref_ref"}};
+const struct symmode SYMTAB_NOERR[1] = {{"sym_noerror"}};
+const struct symmode SYMTAB_CREATE[1] = {{"sym_create"}};
+const struct symmode SYMTAB_EXISTING[1] = {{"Symbol not found"}};
struct symbol *
-VCC_SymbolGet(struct vcc *tl, vcc_kind_t kind, const char *e, const char *x)
+VCC_SymbolGet(struct vcc *tl, vcc_kind_t kind,
+ const struct symmode *e, const struct symxref *x)
{
struct symtab *st;
struct symbol *sym;
struct token *t0, *tn, *tn1;
+ AN(tl);
+ AN(e);
+ AN(x);
+ AN(x->name);
if (tl->syntax >= VCL_41 && e == SYMTAB_CREATE && kind != SYM_SUB &&
(tl->t->b[0] == 'v'|| tl->t->b[0] == 'V') &&
(tl->t->b[1] == 'c'|| tl->t->b[1] == 'C') &&
@@ -270,7 +276,7 @@ VCC_SymbolGet(struct vcc *tl, vcc_kind_t kind, const char *e, const char *x)
return (sym);
tl->t = VTAILQ_NEXT(tn, list);
if (sym == NULL) {
- VSB_printf(tl->sb, "%s: '", e);
+ VSB_printf(tl->sb, "%s: '", e->name);
for (tn1 = t0; tn1 != tl->t; tn1 = VTAILQ_NEXT(tn1, list))
VSB_printf(tl->sb, "%.*s", PF(tn1));
VSB_printf(tl->sb, "'");
diff --git a/lib/libvcc/vcc_vmod.c b/lib/libvcc/vcc_vmod.c
index c98e261f0..1a5c13453 100644
--- a/lib/libvcc/vcc_vmod.c
+++ b/lib/libvcc/vcc_vmod.c
@@ -402,7 +402,7 @@ vcc_Act_New(struct vcc *tl, struct token *t, struct symbol *sym)
ExpectErr(tl, ID);
t = tl->t;
- sy2 = VCC_SymbolGet(tl, SYM_OBJECT, "Symbol not found", XREF_NONE);
+ sy2 = VCC_SymbolGet(tl, SYM_OBJECT, SYMTAB_EXISTING, XREF_NONE);
ERRCHK(tl);
AN(sy2);
if (sy2->eval_priv == NULL) {
More information about the varnish-commit
mailing list