error-handling-patterns

Codify Go error handling with wrapping, sentinel errors, and custom types.

Updated Aug 27, 2026
One-click install
npx skills add https://github.com/bjaus/dotfiles --skill error-handling-patterns-bjaus
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: error-handling-patterns
Source: https://github.com/bjaus/dotfiles/tree/main/plugin/skills/error-handling-patterns
Command: npx skills add https://github.com/bjaus/dotfiles --skill error-handling-patterns-bjaus

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Go projects often struggle with propagating errors with sufficient context, leading to debugging challenges. This Skill promotes wrapping errors with context, using sentinel errors, and designing custom error types to improve debuggability and API clarity.

Core Features & Use Cases

  • Wrapping errors with context using fmt.Errorf and %w to preserve the error chain.
  • Defining sentinel errors for expected failure modes and checking with errors.Is.
  • Creating custom error types to include structured information and richer messages.
  • Use cases: library authors exposing clear errors, API handlers returning enriched errors, and services enforcing consistent error handling.

Quick Start

Audit the codebase to adopt the conventions: replace plain error returns with context-wrapped errors, introduce sentinel errors for common failures, and add small custom error types where structured data helps debugging. Example: return fmt.Errorf("creating user %s: %w", email, err)

Frequently Asked Questions about error-handling-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I wrap errors with context in Go to improve debuggability?

Wrap errors with context in Go using fmt.Errorf and the %w verb, which preserves the original error chain while appending descriptive context to improve debuggability and traceability.

What is the best way to check for sentinel errors in a Go application?

The best way to check for sentinel errors in Go is defining expected failure modes as sentinel errors and verifying them using errors.Is, which traverses the wrapped error chain to locate a matching target.

When should I create custom error types in Go instead of using sentinel errors?

Create custom error types in Go instead of sentinel errors when you need to include structured information and richer messages, extracting those details downstream using errors.As for API clarity.

How do I standardize Go error handling conventions across a library or service?

Standardize Go error handling conventions by auditing the codebase to replace plain error returns with context-wrapped errors, introducing sentinel errors for common failures, and adding custom error types.

Does this Go error handling pattern rely on external dependencies or the standard library?

This Go error handling pattern relies entirely on standard library features like fmt.Errorf with %w, errors.Is, and errors.As, requiring no external dependencies to implement consistent error propagation.