From a10c5ff3818f4a51afb5e5f5f0263a18ad1290f0 Mon Sep 17 00:00:00 2001 From: Steven Masley Date: Wed, 19 Nov 2025 09:34:19 -0600 Subject: [PATCH] chore: protect build timings insert for invalid enums (#20821) Database insert errors will fail the transaction. So this error is fatal. Properly return it for a better error call stack, and not just hiding the error in the logs. --- coderd/provisionerdserver/provisionerdserver.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/coderd/provisionerdserver/provisionerdserver.go b/coderd/provisionerdserver/provisionerdserver.go index 56670d8a2d..39e707a87f 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