error-handling

Apply Go 1.20+ error handling patterns with multiple `%w` wrapping and slog.

2|Updated Feb 6, 2026
One-click install
npx skills add https://github.com/air-gapped/cooked --skill error-handling-air-gapped
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: error-handling
Source: https://github.com/air-gapped/cooked/tree/main/.claude/skills/error-handling
Command: npx skills add https://github.com/air-gapped/cooked --skill error-handling-air-gapped

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Go programs often struggle with scalable error handling as codebases grow. This skill presents patterns for multi-error wrapping, preserving context, and integrating structured logging to improve reliability and debuggability.

Core Features & Use Cases

  • Multi-error wrapping with errors.Join to preserve all failure causes.
  • Wrapping with multiple %w in fmt.Errorf to retain rich context across layers.
  • Correct unwrap semantics and guidance to use errors.Is / errors.As for robust error checks.
  • Slog integration patterns for consistent, structured logging across services.
  • Use case: when aggregating results from several calls, this skill helps you return a single, rich error that preserves all underlying causes.

Quick Start

Review and apply the patterns to existing Go code: replace plain error returns with errors.Join where appropriate, adopt %w wrapping for context, implement errors.Is/errors.As checks in call sites, and align logging with slog for observability.

Frequently Asked Questions about error-handling

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

FAQPage Schema
How do I handle multiple errors in Go and preserve all failure causes?

Handle multiple Go errors by using errors.Join to aggregate failures into a single error, preserving all underlying causes. This pattern is ideal for aggregating results from several calls while maintaining rich context across microservices and CLI tools.

What is the best way to wrap Go errors with context across service layers?

The best way to wrap Go errors is using fmt.Errorf with multiple %w verbs to retain rich context across layers. This preserves the error chain, allowing callers to unwrap and inspect underlying causes robustly.

How does errors.Is and errors.As work with wrapped Go errors?

errors.Is and errors.As work by traversing the error chain created by %w wrapping or errors.Join. They robustly check if a specific error or error type exists in the chain, ensuring accurate error matching across layers.

Can I integrate Go error handling with slog for structured logging?

Yes, you can integrate Go error handling with slog for structured logging. Aligning error propagation with slog-friendly logging preserves error chains and debuggability, ensuring consistent observability across microservices.

Does this Go error handling approach work for Go 1.20 and above?

Yes, this approach applies to Go 1.20+ projects. It enforces usage of errors.Join and multiple %w wrapping, which are features available in these versions, ensuring robust error reporting and clean propagation in libraries and microservices.

When should I use errors.Join instead of fmt.Errorf for Go errors?

Use errors.Join when aggregating results from several calls into a single error to preserve all failure causes. Use fmt.Errorf with %w when you need to add contextual information to a single error across different layers.