go-error-handling

Design Go error handling with wrapping, inspection, and logging strategies.

8|Updated Jun 5, 2026
One-click install
npx skills add https://github.com/muratmirgun/gophers --skill go-error-handling-muratmirgun
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: go-error-handling
Source: https://github.com/muratmirgun/gophers/tree/main/skills/go-error-handling
Command: npx skills add https://github.com/muratmirgun/gophers --skill go-error-handling-muratmirgun

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill helps you design, propagate, inspect, and log Go errors correctly so failures remain debuggable without breaking API boundaries or creating duplicate logs.

Core Features & Use Cases

  • Error strategy selection: Choose between opaque, sentinel, typed, or joined errors based on how callers need to react.
  • Wrapping and inspection: Preserve identity with %w, inspect with errors.Is and errors.As, and avoid string matching.
  • Production-safe flow: Follow the log-or-return rule, reduce nesting with guard clauses, and use panic or recover only at the proper boundary.
  • Use case: When a service call fails, this Skill guides you to wrap the error with useful context, return it once, and let the top-level handler decide whether to log or translate it.

Quick Start

Use this skill to review my Go function for error handling, choose the right error strategy, and rewrite it to wrap context correctly without duplicate logging.

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 in Go without creating duplicate logs?

To wrap errors in Go without duplicate logs, follow the log-or-return rule: wrap the error with %w for context, return it once, and let the top-level handler decide whether to log or translate it.

What's the best way to choose between sentinel, typed, and opaque errors in Go?

Choosing between sentinel, typed, and opaque errors in Go depends on how callers need to react: use opaque errors when callers only log, sentinel for specific checks with errors.Is, and typed for extracting structured data with errors.As.

How do I inspect wrapped errors using errors.Is and errors.As?

Inspect wrapped errors in Go using errors.Is to check for specific sentinel values and errors.As to extract typed error structures, avoiding fragile string matching while preserving error identity through the %w wrapping verb.

When should I use errors.Join instead of %w for Go error handling?

Use errors.Join in Go when you need to combine multiple independent errors into a single error value, whereas %w is for adding contextual information to a single underlying error during propagation.

Why does my Go error handling break API boundaries when returning errors?

Go error handling breaks API boundaries when internal errors leak through opaque returns or string matching. Preserve API stability by selecting appropriate error strategies and using errors.Is and errors.As for safe inspection.

Can I migrate existing Go functions to use joined error strategies?

You can migrate Go functions to joined error strategies by analyzing boundary layers, applying errors.Join for multiple failures, and using single-point logging to maintain debuggability and API stability.