Skip to content

go.sentinel_error_comparison

Correctness Medium

Detects error comparisons using == or string matching instead of errors.Is().

Direct error comparison:

  • Misses wrapped errorsfmt.Errorf("%w", err) won’t match
  • Breaks error chains — Go 1.13+ error wrapping is ignored
  • Fragile — String comparisons break on message changes
// ❌ 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
}
  • err == sentinel comparisons
  • err.Error() == "..." string comparisons
  • Missing errors.Is() usage

Unfault replaces direct comparison with errors.Is():

if errors.Is(err, sql.ErrNoRows) {
// ...
}