Why this matters
Reduces information leakage, improves security, and keeps public errors stable.
Do not include internal identifiers (DB IDs, service IDs, tokens) in client-facing errors. Log them internally; return generic messages externally.
Reduces information leakage, improves security, and keeps public errors stable.
Side-by-side examples engineers can pattern-match during review.
return fmt.Errorf("serviceId %s not found", serviceID)logger.Error("resource not found", "service_id", serviceID)
return ErrNotFoundfmt.Errorf("pk=%s invalid", pk)logger.Error("invalid", "pk", pk); return ErrInvalidFrom the same buckets as this rule.
Check if loops use equality operators (== or !=) in termination conditions. These can lead to infinite loops if the condition is never met exactly. Instead, use relational operators like < or > for safer loop termination.