internal/postgres: treat a zero commit time as a bad module

Previously, a zero commit time in a module caused it to be
reprocessed. Instead, it should fail permanently.

Fixes b/162315868.

Change-Id: I68f36b29dce41690abeca26ac0908ddc0a109af9
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/245918
Reviewed-by: Julie Qiu <julie@golang.org>
diff --git a/internal/postgres/insert_module.go b/internal/postgres/insert_module.go
index f89c81a..ec4f8e7 100644
--- a/internal/postgres/insert_module.go
+++ b/internal/postgres/insert_module.go
@@ -45,6 +45,10 @@
 	if err := validateModule(m); err != nil {
 		return err
 	}
+	// The proxy accepts modules with zero commit times, but they are bad.
+	if m.CommitTime.IsZero() {
+		return fmt.Errorf("empty commit time: %w", derrors.BadModule)
+	}
 	// Compare existing data from the database, and the module to be
 	// inserted. Rows that currently exist should not be missing from the
 	// new module. We want to be sure that we will overwrite every row that
@@ -569,9 +573,11 @@
 	return version == v, nil
 }
 
-// validateModule checks that fields needed to insert a module into the
-// database are present. Otherwise, it returns an error listing the reasons the
-// module cannot be inserted.
+// validateModule checks that fields needed to insert a module into the database
+// are present. Otherwise, it returns an error listing the reasons the module
+// cannot be inserted. Since the problems it looks for are most likely on our
+// end, the underlying error it returns is always DBModuleInsertInvalid, meaning
+// that this module should be reprocessed.
 func validateModule(m *internal.Module) (err error) {
 	defer func() {
 		if err != nil {
@@ -603,9 +609,6 @@
 	if len(m.LegacyPackages) == 0 {
 		errReasons = append(errReasons, "module does not have any packages")
 	}
-	if m.CommitTime.IsZero() {
-		errReasons = append(errReasons, "empty commit time")
-	}
 	if len(errReasons) != 0 {
 		return fmt.Errorf("cannot insert module %q: %s", m.Version, strings.Join(errReasons, ", "))
 	}
diff --git a/internal/postgres/insert_module_test.go b/internal/postgres/insert_module_test.go
index 8420805..d4cb743 100644
--- a/internal/postgres/insert_module_test.go
+++ b/internal/postgres/insert_module_test.go
@@ -229,7 +229,7 @@
 			}(),
 			wantVersion:    sample.VersionString,
 			wantModulePath: sample.ModulePath,
-			wantWriteErr:   derrors.DBModuleInsertInvalid,
+			wantWriteErr:   derrors.BadModule,
 		},
 	}