Why this matters
Enables safe retries, correct surfacing of validation/constraint failures, and better diagnostics.
Detect transient vs non-transient DB errors; add context and apply retry policies only where safe (idempotent reads/operations).
Enables safe retries, correct surfacing of validation/constraint failures, and better diagnostics.
Side-by-side examples engineers can pattern-match during review.
catch (DbUpdateException ex) { /* ignore or generic */ }catch (DbUpdateException ex) {
_log.LogError(ex, "DB update failed");
if (IsUniqueConstraintViolation(ex)) return Conflict();
throw;
}catch(DbUpdateException){ /* swallow */ }catch(DbUpdateException e){ if(IsUnique(e)) return Conflict(); throw; }From the same buckets as this rule.
Review SQL/database migrations for operations that can lock large tables or cause downtime. Examples: creating indexes without CONCURRENTLY (Postgres), ALTER COLUMN TYPE on big tables, adding NOT NULL without backfill, long-running updates without batching. Require an online migration strategy (CONCURRENTLY, backfill in batches, dual-write/expand-contract) and a rollback plan.