mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
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.
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user