From 1c2823677dca00072bd8af452ae5bd5cc2466086 Mon Sep 17 00:00:00 2001 From: Jacek Migdal Date: Thu, 23 May 2024 12:37:48 +0200 Subject: [PATCH] Panic less (#201) This not only cause panic, but also makes query never finish and our debugging sucks. Found during Hydr --- quesma/quesma/search.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/quesma/quesma/search.go b/quesma/quesma/search.go index 258c6054e..fc198f13a 100644 --- a/quesma/quesma/search.go +++ b/quesma/quesma/search.go @@ -215,6 +215,11 @@ func (q *QueryRunner) handleSearchCommon(ctx context.Context, indexPattern strin }) columnsSlice := [][]string{columns} translatedQueryBody, hitsSlice := q.searchWorker(ctx, queries, columnsSlice, table, doneCh, optAsync) + if len(hitsSlice) == 0 { + logger.ErrorWithCtx(ctx).Msgf("no hits, queryInfo: %d", translatedQueryBody) + doneCh <- AsyncSearchWithError{translatedQueryBody: translatedQueryBody, err: errors.New("no hits")} + return + } searchResponse, err := queryTranslator.MakeSearchResponse(hitsSlice[0], queries[0]) if err != nil { logger.ErrorWithCtx(ctx).Msgf("error making response: %v, queryInfo: %+v, rows: %v", err, queries[0].QueryInfo, hitsSlice[0])