internal/postgres: detect missing row in paths table

We occasionally see what we think a failure of insertPaths to
insert all the rows missing from the paths table. Add a check
to confirm that hypothesis.

Change-Id: I15fd8b1d7a1b999a7dfbbe5ca2d93419b90af41d
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/288830
Trust: Jonathan Amsterdam <jba@google.com>
Run-TryBot: Jonathan Amsterdam <jba@google.com>
TryBot-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Julie Qiu <julie@golang.org>
diff --git a/internal/postgres/insert_module.go b/internal/postgres/insert_module.go
index fad2ae4..3ee2374 100644
--- a/internal/postgres/insert_module.go
+++ b/internal/postgres/insert_module.go
@@ -314,7 +314,10 @@
 			}
 		}
 		v1path := internal.V1Path(u.Path, m.ModulePath)
-		pathID := pathToID[u.Path]
+		pathID, ok := pathToID[u.Path]
+		if !ok {
+			return fmt.Errorf("no entry in paths table for %q; should be impossible", u.Path)
+		}
 		pathIDToPath[pathID] = u.Path
 		unitValues = append(unitValues,
 			pathID,