golang-error-handling

Enforce idiomatic Go error handling with %w wrapping and errors.Is/As.

Updated Mar 8, 2026
One-click install
npx skills add https://github.com/tamago0224/kuroshio-mta --skill golang-error-handling-tamago0224
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-error-handling
Source: https://github.com/tamago0224/kuroshio-mta/tree/main/.agents/skills/golang-error-handling
Command: npx skills add https://github.com/tamago0224/kuroshio-mta --skill golang-error-handling-tamago0224

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Inconsistent and non-idiomatic error handling in Go code leads to silent failures, duplicate logs, high-cardinality messages, and lost context that break observability and incident response. This Skill codifies a single-handling rule, idiomatic wrapping and inspection patterns, and structured logging practices so teams can reliably surface actionable errors without overwhelming aggregators.

Core Features & Use Cases

  • Enforce wrapping and inspection: guidance to create and wrap errors with %w, and to inspect chains with errors.Is and errors.As.
  • Combine and collect errors: advice on using errors.Join for multi-error scenarios and validating multiple items without early exit.
  • Single-handling rule & panic guidance: detect and avoid log-and-return patterns, and prescribe panic/recover practices at goroutine boundaries.
  • Structured observability: recommend slog for structured logging and samber/oops for production errors with attributes and stack traces, keeping error messages low-cardinality.
  • Use cases: writing new error-handling code, reviewing PR diffs for swallowed or mis-wrapped errors, and running large audits across repositories to surface violations.

Quick Start

Apply the golang-error-handling skill to review the attached Go files, wrap errors with %w where appropriate, replace log-and-return patterns with structured slog logging at the top level, and ensure variable data is carried as structured attributes rather than interpolated into error strings.

Frequently Asked Questions about golang-error-handling

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

FAQPage Schema
How do I enforce idiomatic Go error handling in my codebase?

Idiomatic Go error handling enforces wrapping with %w, inspects chains via errors.Is and errors.As, and uses errors.Join for multi-error scenarios to preserve context and ensure diagnosable failures. It detects single-handling violations and mis-wrapped errors across repositories.

What is the best way to avoid log-and-return patterns in Go?

The best way to avoid log-and-return patterns in Go is applying a single-handling rule: return errors wrapped with %w immediately, and defer structured slog logging to the top level. This prevents duplicate logs and lost error context during incident response.

How does errors.Join work for collecting multiple errors in Go?

errors.Join combines multiple Go errors into a single chain, allowing validation of multiple items without early exit. It preserves the individual error contexts so callers can inspect the combined chain using errors.Is or errors.As for comprehensive failure analysis.

When do I need structured logging with slog for Go errors?

Structured logging with slog is needed when you want low-cardinality error messages and actionable observability. You attach variable data as structured attributes rather than interpolating strings, keeping error chains intact for aggregators and incident response.

Does samber/oops integrate with slog for production Go error tracking?

Yes, samber/oops integrates with slog to provide production-ready Go errors with structured attributes and stack traces. It ensures low-cardinality messages and preserves error chains, keeping error observability consistent without overwhelming log aggregators.

What are the limitations of interpolating variable data into Go error strings?

Interpolating variable data into Go error strings creates high-cardinality messages that overwhelm log aggregators and break observability. It loses structured context, making errors less diagnosable; carrying data as slog attributes or samber/oops structured fields preserves error chains.