cxuu avatar

Go Error Handling

Go error strategy guide covering sentinel errors, custom types, and %w versus %v wrapping choices.

skills.sh installs
1.4K
GitHub stars
196
last updated
Aug 21, 2026
View on GitHub

Own this skill? Claim it

What it does

  • Covers choosing between sentinel errors, typed errors, and opaque errors, plus when to wrap with %w versus %v
  • Includes a check script (check-errors.sh) that flags string-based error matching, bare propagation, and log-and-return patterns
  • Enforces handling each error once, either logging or returning it, and never discarding errors with _ without a comment
  • Designed for Go developers writing error flow across package boundaries who need errors.Is and errors.As to work reliably

Install

$ npx -y skills add cxuu/golang-skills --skill go-error-handling -y

Installs into .agents/skills for every agent it finds here, and .claude/skills for Claude Code.

Files

Go Error Handling

Compatibility: errors.Is, errors.As, and %w wrapping require Go 1.13+; structured logging examples may use log/slog from Go 1.21+.

Resource Routing

  • scripts/check-errors.sh - Run when checking string-based error matching, bare error propagation, and log-and-return patterns.
  • scripts/check-errors-ast.go - Implementation helper invoked by check-errors.sh; patch this when changing error-flow analysis behavior.
  • references/ERROR-FLOW.md - Read when deciding where to handle, wrap, log, or return errors.
  • references/ERROR-TYPES.md - Read when choosing sentinel errors, typed errors, or opaque errors.
  • references/WRAPPING.md - Read when choosing %w versus %v or crossing package boundaries.

In Go, errors are values — they are created by code and consumed by code.

Choosing an Error Strategy

Details

Repository
github.com/cxuu/golang-skills
Categories
Go, Code Review & Quality
First seen
May 16, 2026

More from cxuu/golang-skills

All 20

Similar to Go Error Handling

More Go