Monorepo for Tangled tangled.org

appview/db: cure a few panics

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 <me@oppi.li>

oppi.li bf375e1e 3cfae495

verified
Changed files
+3 -2
appview
db
+3 -2
appview/db/db.go
··· 653 653 // if we have `FilterIn(k, [1, 2, 3])`, compile it down to `k in (?, ?, ?)` 654 654 if kind == reflect.Slice || kind == reflect.Array { 655 655 if rv.Len() == 0 { 656 - panic(fmt.Sprintf("empty slice passed to %q filter on %s", f.cmp, f.key)) 656 + // always false 657 + return "1 = 0" 657 658 } 658 659 659 660 placeholders := make([]string, rv.Len()) ··· 672 673 kind := rv.Kind() 673 674 if kind == reflect.Slice || kind == reflect.Array { 674 675 if rv.Len() == 0 { 675 - panic(fmt.Sprintf("empty slice passed to %q filter on %s", f.cmp, f.key)) 676 + return nil 676 677 } 677 678 678 679 out := make([]any, rv.Len())