go-error-handling

Installation
SKILL.md

Go Error Handling Skill

Idiomatic Go error handling through context-rich wrapping, sentinel errors, custom error types, and proper error chain inspection. Every error return tells a story -- when read top-to-bottom, wrapped errors form a narrative of what happened and where.

Available Scripts

  • scripts/check-errors.sh -- Detect bare return err and log-and-return anti-patterns. Run bash scripts/check-errors.sh --help for options.

Instructions

Phase 1: Understand the Context

Read the repository CLAUDE.md before implementing any error handling, because project-specific conventions (error prefixes, logging patterns, custom base types) override generic Go idioms.

Scan existing error patterns in the package to understand what is already in use. When gopls MCP is available, use go_symbol_references to find all usages of sentinel errors across the codebase, and go_diagnostics to verify error handling correctness after edits. Fallback: gopls references CLI or LSP tool.

Phase 2: Select the Right Error Pattern

Choose the simplest pattern that fits the situation, because over-engineering error types creates unnecessary abstraction that callers must learn and maintain. A simple wrap handles most cases; do not create custom types when a sentinel suffices, or sentinels when a simple wrap is enough.

Related skills
Installs
5
GitHub Stars
366
First Seen
Mar 23, 2026