go.sentinel_error_comparison
Correctness
Medium
Detects error comparisons using == or string matching instead of errors.Is().
Why It Matters
Section titled “Why It Matters”Direct error comparison:
- Misses wrapped errors —
fmt.Errorf("%w", err)won’t match - Breaks error chains — Go 1.13+ error wrapping is ignored
- Fragile — String comparisons break on message changes
Example
Section titled “Example”// ❌ Before (broken with wrapped errors)if err == sql.ErrNoRows { return nil}
if err.Error() == "not found" { return nil}// ✅ After (handles wrapped errors)if errors.Is(err, sql.ErrNoRows) { return nil}What Unfault Detects
Section titled “What Unfault Detects”err == sentinelcomparisonserr.Error() == "..."string comparisons- Missing
errors.Is()usage
Auto-Fix
Section titled “Auto-Fix”Unfault replaces direct comparison with errors.Is():
if errors.Is(err, sql.ErrNoRows) { // ...}