Skip to main content

Writing Error Messages That Actually Help Debugging

1 min read

The bad

Error: connection failed

The good

Error: connection to postgresql://db.internal:5432/warehouse failed
  after 5 retries (timeout: 3s each). Database may be unreachable
  or credentials may be incorrect. Check: (1) is the DB instance
  running? (2) is the security group open on port 5432?

A template

fmt.Errorf("failed to %s %s: %w — try %s",
    action, target, err, suggestion)

What I learned

Writing good error messages is a multiplier. One good message saves three Slack messages, one PagerDuty call, and one “can you check if…” question. Invest the 10 extra seconds.