internal/vuln: log nil OSV entries
We saw this error recently:
Error executing page template "vuln/list": template: list.tmpl:44:25:
executing "main-content" at <.ID>: nil pointer evaluating *osv.Entry.ID
That seems to be because an *osv.Entry is nil, which shouldn't happen.
Add logging to try to understand why.
Change-Id: I3eb5b992d6b29f2cbf024b120e6221812faa7db1
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/542875
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
Auto-Submit: Jonathan Amsterdam <jba@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Run-TryBot: Jonathan Amsterdam <jba@google.com>
kokoro-CI: kokoro <noreply+kokoro@google.com>
diff --git a/internal/vuln/client.go b/internal/vuln/client.go
index bc53bc6..16b87eb 100644
--- a/internal/vuln/client.go
+++ b/internal/vuln/client.go
@@ -13,6 +13,7 @@
"strings"
"golang.org/x/pkgsite/internal/derrors"
+ "golang.org/x/pkgsite/internal/log"
"golang.org/x/pkgsite/internal/osv"
"golang.org/x/pkgsite/internal/stdlib"
"golang.org/x/sync/errgroup"
@@ -228,7 +229,18 @@
ids = ids[:n]
}
- return c.byIDs(ctx, ids)
+ entries, err := c.byIDs(ctx, ids)
+ if err != nil {
+ return nil, err
+ }
+ // We've seen nil entries crash the vuln/list page.
+ // Add logging to understand why.
+ for i, e := range entries {
+ if e == nil {
+ log.Errorf(ctx, "Client.Entries: got nil osv.Entry for ID %q", ids[i])
+ }
+ }
+ return entries, nil
}
func sortIDs(ids []string) {