From bf375e1e0cd6a96eed02909f24a4d4a82a6056ee Mon Sep 17 00:00:00 2001 From: oppiliappan Date: Mon, 4 Aug 2025 17:36:20 +0100 Subject: [PATCH] appview/db: cure a few panics Change-Id: ukznmmplmlulvlmmulnkzrzkknknlyyu when db.FilterIn(array) is used, the query compiler would panic on empty lists: db.GetPipelineStatuses( s.db, db.FilterEq("repo_owner", repoInfo.OwnerDid), db.FilterEq("repo_name", repoInfo.Name), db.FilterEq("knot", repoInfo.Knot), db.FilterIn("sha", shas), ) if `shas` was constructed to be an empty list, it would suffice for the filter to always fail and subsequently affect zero rows. Signed-off-by: oppiliappan --- appview/db/db.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/appview/db/db.go b/appview/db/db.go index 5f65cd2..ef5aa13 100644 --- a/appview/db/db.go +++ b/appview/db/db.go @@ -653,7 +653,8 @@ func (f filter) Condition() string { // if we have `FilterIn(k, [1, 2, 3])`, compile it down to `k in (?, ?, ?)` if kind == reflect.Slice || kind == reflect.Array { if rv.Len() == 0 { - panic(fmt.Sprintf("empty slice passed to %q filter on %s", f.cmp, f.key)) + // always false + return "1 = 0" } placeholders := make([]string, rv.Len()) @@ -672,7 +673,7 @@ func (f filter) Arg() []any { kind := rv.Kind() if kind == reflect.Slice || kind == reflect.Array { if rv.Len() == 0 { - panic(fmt.Sprintf("empty slice passed to %q filter on %s", f.cmp, f.key)) + return nil } out := make([]any, rv.Len()) -- 2.43.0