commit 99f694271cf527c9aaaf351d1c7e7177461bb9f5
parent ec8e5b1a049d2bd216c8df94d406d1193e0fe373
Author: Pavel Renev <an2qzavok@gmail.com>
Date: Mon, 19 Feb 2024 23:11:15 +0000
wdb: don't crash on tests, offer a more useful debug message instead
Diffstat:
2 files changed, 15 insertions(+), 6 deletions(-)
diff --git a/src/tablist/tablist.h b/src/tablist/tablist.h
@@ -42,4 +42,4 @@ TLencoder * initTLencoder(Slice *);
int TLencode(TLencoder *, char *, usize);
TLnode * TLgetnode(Slice *, char *, char *);
-char * TLval2str(TLnode *);
-\ No newline at end of file
+char * TLval2str(TLnode *);
diff --git a/src/wdb/search.c b/src/wdb/search.c
@@ -61,11 +61,21 @@ testname(TLnode *n, Reprog *re)
int
testtags(TLnode *n, char *field, char **tags)
{
+ int i;
+ char uuid[64], *str;
if (tags[0] == nil) return 1;
+ i = snprint(uuid, 64, "%.*s\n", n->name->len, n->name->p);
+ uuid[i-1] = 0;
TLnode *nfield = TLgetnode(n->children, field, nil);
- if (nfield == nil) sysfatal("testtags: can't get tags node %s", field);
- char *str = TLval2str(nfield);
- if (str == nil) sysfatal("testtags: can't get tags value %s", field);
+ if (nfield == nil) {
+ fprint(2, "can't get node %s→%s\n", uuid, field);
+ return 0;
+ }
+ str = TLval2str(nfield);
+ if (str == nil) {
+ fprint(2, "can't get value %s→%s\n", uuid, field);
+ return 0;
+ }
char *test[MaxTags];
int N = tokenize(str, test, MaxTags);
test[N] = nil;
@@ -77,7 +87,7 @@ testtags(TLnode *n, char *field, char **tags)
void
usage(void)
{
- fprint(2, "usage: %s [-t tags] [query]\n", argv0);
+ fprint(2, "usage: %s [-t tags] [-T type] [query]\n", argv0);
exits("usage");
}