forked from tangled.org/core
this repo has no description

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>

Changed files
+3 -2
appview
db
+3 -2
appview/db/db.go
···
// 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())
···
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())