go-error-handling

Apply idiomatic Go error wrapping with %w and sentinel errors.

415|44|Updated Mar 18, 2026
One-click install
npx skills add https://github.com/notque/claude-code-toolkit --skill go-error-handling-notque
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: go-error-handling
Source: https://github.com/notque/claude-code-toolkit/tree/main/skills/go-error-handling
Command: npx skills add https://github.com/notque/claude-code-toolkit --skill go-error-handling-notque

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires bash, find, sed, basename, and includes scripts (resource) and references (resource) components.

What problem does it solve?

This skill provides guidance on implementing idiomatic Go error handling, including wrapping with context, using sentinel and custom error types, and preserving error chains with %w for robust propagation across your codebase. It emphasizes avoiding naked returns and ensuring errors are meaningful at the boundaries.

Core Features & Use Cases

  • Guiding idiomatic error wrapping with context
  • Defining sentinel errors for API boundaries
  • Creating custom error types that support Unwrap and errors.Is/As
  • Mapping domain errors to HTTP status codes at handler boundaries

Quick Start

Provide a Go function with an error, and ask Claude to apply idiomatic wrapping, sentinel or custom errors, and proper unwrapping to preserve the error chain.

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 context in Go?

Idiomatic Go error handling uses the %w verb in fmt.Errorf to wrap errors with context, preserving the error chain for robust propagation across your codebase boundaries.

What is the best way to define sentinel errors in Go?

The best way to define sentinel errors in Go is declaring them as package-level vars using errors.New, enabling consistent checks via errors.Is across API boundaries.

How do I implement custom error types that support Unwrap in Go?

To implement custom Go error types, define a struct satisfying the error interface and add an Unwrap method, enabling errors.Is and errors.As to traverse custom error chains.

How do I map domain errors to HTTP status codes in Go handlers?

Map domain errors to HTTP status codes in Go by checking sentinel errors with errors.Is at the HTTP handler boundary, translating domain failures into appropriate HTTP response codes.

Why does my Go error unwrapping fail to find the target error?

Go error unwrapping fails when custom error types lack an Unwrap method or errors use %v instead of %w, breaking the chain required by errors.Is and errors.As.