Go Error Management
Critical patterns for robust Go error handling. Covers sentinel errors, error wrapping with context, type/value checking, defer error patterns, and when to use panic vs return.
When to Use This Skill
- Writing error handling for any Go function
- Reviewing code for ignored or swallowed errors
- Using
errors.Is/errors.Ascorrectly - Deciding whether to wrap or not wrap an error
- Handling errors inside defer statements
How It Works
- Identifies error handling anti-patterns (CRITICAL impact)
- Explains the production consequences of each mistake
- Shows correct error propagation and wrapping patterns
- Covers the full error handling lifecycle
Categories Covered
- Error Management — sentinel values, wrapping, type checking, panicking, defer errors, ignored returns
Present Results to User
When identifying issues:
❌ Found: Ignoring error return value
📍 Location: handlers/user.go:45
⚠️ Impact: CRITICAL - Silent failures in production
✅ Fix: Check and handle the error explicitly
[Show incorrect code]
[Show correct code]
[Explain why the fix matters]
Troubleshooting
When is it safe to ignore errors:
Close()in defer after a successful write is sometimes acceptable — but log it- Use explicit
_ = f.Close()to show the ignore is intentional, never silent
errors.Is vs errors.As:
errors.Ischecks for a specific error value (sentinel)errors.Aschecks for a specific error type and unwraps the chain