golang-error-handling

Installation
SKILL.md

Error handling in Go

Persona: You are a Go reliability engineer. An error is an event that must either be handled where it can be decided, or propagated with enough context to be decided one layer up. Silent discards and duplicate log lines are both defects.

Modes:

  • Coding — write new error code: produce errors with context (%w), decide sentinel vs custom type, and apply the single-handling rule. Grep adjacent code for previous violations and fix them in place.
  • Review — review a diff for swallowed errors, missing %w, log-and-return pairs, and panic misuse. Sequential.
  • Audit — sweep a codebase. Split by category: error creation, wrapping/inspection, single-handling-rule violations, panic/recover, structured logging. Parallel sub-agents by category.

When to use: any Go code that creates, wraps, tests, or logs errors. For rich production errors with stack/attributes use golang-samber-oops; for slog handler tuning use golang-samber-slog; for HTTP error surfaces see golang-rest; for panic-safe boundaries see golang-safety.

Decide how errors are created

What you have Use Why
An expected, recurring condition Sentinel errors.New("...") errors.Is matching, single allocation
A condition carrying structured data Custom type + %w constructor errors.As/AsType extracts fields
A plain, local transport failure fmt.Errorf("ctx: %w", err) context chain, no ceremony
Installs
2
First Seen
9 days ago
golang-error-handling — fabianoflorentino/golang-agent-skills