diff --git a/coderd/provisionerdserver/provisionerdserver.go b/coderd/provisionerdserver/provisionerdserver.go index 56670d8a2d9e8..39e707a87f016 100644 --- a/coderd/provisionerdserver/provisionerdserver.go +++ b/coderd/provisionerdserver/provisionerdserver.go @@ -2175,6 +2175,12 @@ func (s *server) completeWorkspaceBuildJob(ctx context.Context, job database.Pro continue } + // Scan does not guarantee validity + if !stg.Valid() { + s.Logger.Warn(ctx, "invalid stage, will fail insert based one enum", slog.F("value", t.Stage)) + continue + } + params.Stage = append(params.Stage, stg) params.Source = append(params.Source, t.Source) params.Resource = append(params.Resource, t.Resource) @@ -2184,8 +2190,11 @@ func (s *server) completeWorkspaceBuildJob(ctx context.Context, job database.Pro } _, err = db.InsertProvisionerJobTimings(ctx, params) if err != nil { - // Log error but don't fail the whole transaction for non-critical data + // A database error here will "fail" this transaction. Making this error fatal. + // If this error is seen, add checks above to validate the insert parameters. In + // production, timings should not be a fatal error. s.Logger.Warn(ctx, "failed to update provisioner job timings", slog.F("job_id", jobID), slog.Error(err)) + return xerrors.Errorf("update provisioner job timings: %w", err) } // On start, we want to ensure that workspace agents timeout statuses