z-go-errors
Installation
SKILL.md
Go errors
Core rules
- Check every error — never discard with
_. - Wrap with context:
fmt.Errorf("create user: %w", err)— short prefix, lowercase, no period. - Translate errors at transport boundaries —
%vremoves wrapping but does not sanitize the message. Return stable public errors; retain internal causes for one safe log. - Inspect via
errors.Is/errors.As— never==on wrapped errors or bare type assertions. - Handle exactly once — log OR return, never both (see Single Handling below).
- Panic only for truly unrecoverable states — programmer errors, broken invariants; never for expected conditions.
Wrapping and inspection
// wrap
return fmt.Errorf("fetch user %s: %w", id, err)
// sentinel check — works through the chain
if errors.Is(err, ErrNotFound) { ... }