go-error-handling

Installation
SKILL.md

Go Error Handling

Go's explicit error handling is a feature, not a limitation. These patterns ensure errors are informative, actionable, and properly propagated.

1. Error Decision Tree

When creating or returning an error, follow this tree:

  1. Simple, no extra context needed?errors.New("message")
  2. Need to add context to existing error?fmt.Errorf("doing X: %w", err)
  3. Caller needs to detect this error? → Sentinel var or custom type
  4. Error carries structured data? → Custom type implementing error
  5. Propagating from downstream? → Wrap with %w and add context

2. Sentinel Errors

Use package-level var for errors that callers need to check:

Related skills
Installs
52
GitHub Stars
56
First Seen
Mar 27, 2026