Use when writing Go code that returns, wraps, or handles errors — choosing between sentinel errors, custom types, and fmt.Errorf (%w vs %v), structuring error…
Go Error Handling
Available Scripts
scripts/check-errors.sh — Detects error handling anti-patterns: string comparison on err.Error(), bare return err without context, and log-and-return violations. Run bash scripts/check-errors.sh --help for options.
In Go, errors are values — they are
created by code and consumed by code.
Choosing an Error Strategy
System boundary (RPC, IPC, storage)? → Wrap with %v to avoid leaking internals
Caller needs to match specific conditions? → Sentinel or typed error, wrap with %w
Caller just needs debugging context? → fmt.Errorf("...: %w", err)
Leaf function, no wrapping needed? → Return the error directly
Default: wrap with %w and place it at the end of the format string.don't have the plugin yet? install it then click "run inline in claude" again.