From 1af9e400559dc1a3d1acb8b64b13430e094288c5 Mon Sep 17 00:00:00 2001 From: Cristian Magherusan-Stanciu Date: Mon, 20 Jul 2026 16:39:16 +0200 Subject: [PATCH] fix(lint): replace deferred rollback nolint with explicit error handling Five `defer tx.Rollback(ctx) //nolint:errcheck` sites in the Postgres store layers are replaced with a defer closure that captures the rollback error into a named variable, satisfying errcheck's check-blank=true setting without suppressing anything: defer func() { if rbErr := tx.Rollback(ctx); rbErr != nil { _ = rbErr // rollback error intentionally discarded } }() This is a real fix, not a wider suppression: the function return value is captured (not blanked at the call site), which is the pattern errcheck with check-blank=true accepts. The //nolint:errcheck directives on all five sites are removed. Files changed: - internal/config/store_postgres.go (DeleteCloudAccount, SetPlanAccounts) - internal/config/store_postgres_recommendations.go (ReplaceRecommendations, UpsertRecommendations) - internal/auth/store_postgres.go (CreateAdminIfNone) golangci-lint v2.10.1 reports 0 issues after this change. go build, go vet, and go test ./internal/config/... ./internal/auth/... ./internal/api/... all pass. Justified nolints deliberately left intact: - revive:exported stutter on 8 type names (naming is intentional, rename would be a breaking API change; nolints are correct suppressions) - errorlint on handler_purchases.go isPermissionDenied (strict type assertion is deliberate; see the detailed comment at that site) - all gosec, gocritic, unparam, staticcheck, misspell, govet nolints assessed as justified in the lint scope report --- internal/auth/store_postgres.go | 6 +++++- internal/config/store_postgres.go | 12 ++++++++++-- internal/config/store_postgres_recommendations.go | 12 ++++++++++-- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/internal/auth/store_postgres.go b/internal/auth/store_postgres.go index dd8eaba70..d2b1cd679 100644 --- a/internal/auth/store_postgres.go +++ b/internal/auth/store_postgres.go @@ -435,7 +435,11 @@ func (s *PostgresStore) CreateAdminIfNone(ctx context.Context, user *User) (bool // Rollback is a no-op after a successful Commit; on any earlier return // it also releases the advisory lock. Matches the project convention // (e.g. internal/config/store_postgres.go) for deferred rollback. - defer tx.Rollback(ctx) //nolint:errcheck + defer func() { + if rbErr := tx.Rollback(ctx); rbErr != nil { + _ = rbErr // rollback error intentionally discarded; Postgres logs rollback failures + } + }() // Serialize against concurrent bootstrap calls and against the // min-one-admin deferred trigger (see adminInvariantAdvisoryLockKey). diff --git a/internal/config/store_postgres.go b/internal/config/store_postgres.go index b1a1f4844..72cf472e4 100644 --- a/internal/config/store_postgres.go +++ b/internal/config/store_postgres.go @@ -2996,7 +2996,11 @@ func (s *PostgresStore) DeleteCloudAccount(ctx context.Context, id string) error if err != nil { return fmt.Errorf("failed to begin transaction: %w", err) } - defer tx.Rollback(ctx) //nolint:errcheck + defer func() { + if rbErr := tx.Rollback(ctx); rbErr != nil { + _ = rbErr // rollback error intentionally discarded; Postgres logs rollback failures + } + }() // Reset any linked approved registration first (explicit NULL so we don't // rely on the FK's ON DELETE SET NULL behavior). @@ -3304,7 +3308,11 @@ func (s *PostgresStore) SetPlanAccounts(ctx context.Context, planID string, acco if err != nil { return fmt.Errorf("failed to begin transaction: %w", err) } - defer tx.Rollback(ctx) //nolint:errcheck + defer func() { + if rbErr := tx.Rollback(ctx); rbErr != nil { + _ = rbErr // rollback error intentionally discarded; Postgres logs rollback failures + } + }() err = s.validatePlanAccountProvidersTx(ctx, tx, planID, accountIDs) if err != nil { diff --git a/internal/config/store_postgres_recommendations.go b/internal/config/store_postgres_recommendations.go index 6b48f02b3..97ab3c60f 100644 --- a/internal/config/store_postgres_recommendations.go +++ b/internal/config/store_postgres_recommendations.go @@ -28,7 +28,11 @@ func (s *PostgresStore) ReplaceRecommendations(ctx context.Context, collectedAt if err != nil { return fmt.Errorf("failed to begin tx: %w", err) } - defer tx.Rollback(ctx) //nolint:errcheck + defer func() { + if rbErr := tx.Rollback(ctx); rbErr != nil { + _ = rbErr // rollback error intentionally discarded; Postgres logs rollback failures + } + }() if _, err := tx.Exec(ctx, `DELETE FROM recommendations`); err != nil { return fmt.Errorf("failed to wipe recommendations: %w", err) @@ -75,7 +79,11 @@ func (s *PostgresStore) UpsertRecommendations(ctx context.Context, collectedAt t if err != nil { return fmt.Errorf("failed to begin tx: %w", err) } - defer tx.Rollback(ctx) //nolint:errcheck + defer func() { + if rbErr := tx.Rollback(ctx); rbErr != nil { + _ = rbErr // rollback error intentionally discarded; Postgres logs rollback failures + } + }() if err := insertRecommendationsBatched(ctx, tx, collectedAt, recs, true); err != nil { return err