From 746f38849dd939c297fe6fed8877fc9e5114cfc5 Mon Sep 17 00:00:00 2001 From: Stefan Hengl Date: Thu, 1 Feb 2024 09:22:10 +0100 Subject: [PATCH] matchtree: fix panic for missing files (#733) Previously, shards crashed for queries like "foo type:file" if foo was not present. Test plan: updated e2e test --- matchtree.go | 6 ++++++ web/e2e_test.go | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/matchtree.go b/matchtree.go index 8e7b9a7a5..a653c841e 100644 --- a/matchtree.go +++ b/matchtree.go @@ -1330,6 +1330,12 @@ func pruneMatchTree(mt matchTree) (matchTree, error) { } case *fileNameMatchTree: mt.child, err = pruneMatchTree(mt.child) + if err != nil { + return nil, err + } + if mt.child == nil { + return nil, nil + } case *boostMatchTree: mt.child, err = pruneMatchTree(mt.child) if err != nil { diff --git a/web/e2e_test.go b/web/e2e_test.go index 01ca5999c..720712972 100644 --- a/web/e2e_test.go +++ b/web/e2e_test.go @@ -30,6 +30,7 @@ import ( "time" "github.com/google/go-cmp/cmp" + "github.com/sourcegraph/zoekt" "github.com/sourcegraph/zoekt/query" "github.com/sourcegraph/zoekt/rpc" @@ -137,6 +138,9 @@ func TestBasic(t *testing.T) { "/search?q=magic": { `value=magic`, }, + "/search?q=foo+type:file": { + `value=foo`, + }, "/robots.txt": { "disallow: /search", },