go/error-handling

Apply Go error-handling patterns with fmt.Errorf, sentinel errors, and errors.Join.

3|1|Updated Feb 10, 2026
One-click install
npx skills add https://github.com/deandum/claude-resources --skill go-error-handling-deandum
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: go/error-handling
Source: https://github.com/deandum/claude-resources/tree/main/skills/go/error-handling
Command: npx skills add https://github.com/deandum/claude-resources --skill go-error-handling-deandum

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Go projects often struggle with consistent and safe error handling across packages. This Skill provides established patterns for wrapping errors with fmt.Errorf and the %w verb, sentinel errors, custom error types, and multi-error aggregation to improve debuggability and reliability.

Core Features & Use Cases

  • Error Wrapping: propagate context using fmt.Errorf with %w
  • Sentinel Errors: predefined error values for common conditions
  • Custom Error Types: structured error details and extraction with errors.As
  • Multi-Error Collection: aggregating multiple errors with errors.Join
  • HTTP Error Mapping: translate domain errors to HTTP responses
  • Guards and verification: follow best practices and standard error contracts

Quick Start

Ask me to apply the recommended Go error-handling patterns to your codebase.

Frequently Asked Questions about go/error-handling

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

FAQPage Schema
How do I wrap errors with fmt.Errorf in Go?

Wrap errors in Go by using fmt.Errorf with the %w verb to propagate operation context. This preserves the original error chain, allowing callers to inspect underlying causes while adding diagnostic information across package boundaries.

What is the best way to aggregate multiple errors in Go backend services?

Aggregate multiple errors in Go using errors.Join. This function collects multiple error values into a single error, enabling multi-error aggregation for batch operations or validation checks where multiple failures need to be reported together.

How do errors.Is and errors.As work with custom error types in Go?

errors.Is checks if an error matches a specific sentinel value within a wrapped chain, while errors.As extracts structured details from custom error types. Use errors.As to unpack custom error fields for HTTP error mapping and diagnostics.

How do I map Go domain errors to HTTP responses?

Map Go domain errors to HTTP responses by inspecting error chains with errors.Is and errors.As at API boundaries. Translate sentinel errors and custom error types into appropriate HTTP status codes, ensuring consistent error rendering for clients.

When should I use sentinel errors versus custom error types in Go?

Use sentinel errors for predefined common conditions like "not found" or "unauthorized" that require simple equality checks. Use custom error types when you need to carry structured diagnostic data that callers must extract using errors.As.