golang-error-handling

Create idiomatic Go error handling with context wrapping and structured slog logging.

1|Updated May 26, 2026
One-click install
npx skills add https://github.com/tokiou/caba-inseguridad-v2-be --skill golang-error-handling-tokiou
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-error-handling
Source: https://github.com/tokiou/caba-inseguridad-v2-be/tree/main/.claude/skills/golang-error-handling
Command: npx skills add https://github.com/tokiou/caba-inseguridad-v2-be --skill golang-error-handling-tokiou

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

It prevents fragile, inconsistent, and noisy error handling in Go by enforcing idiomatic wrapping, inspection, and safe logging practices that remain useful with log aggregation at scale.

Core Features & Use Cases

  • Idiomatically wrap and inspect errors: Use fmt.Errorf with %w and rely on errors.Is / errors.As (or errors.AsType) so error chains stay traversable across layers.
  • Avoid duplicate noise and swallowed failures: Enforce the single handling rule so errors are either logged or returned, never both, and never silently discarded.
  • Production-ready structured logging guidance: Prefer slog with low-cardinality messages and structured attributes, plus HTTP request logging patterns.
  • Use sentinel errors, custom error types, and errors.Join: Model expected conditions with sentinels, carry structured data with custom types, and combine independent failures cleanly.
  • Use samber/oops for production errors: Add stack traces and structured context without leaking sensitive details to end users.

Quick Start

Apply this skill when creating, wrapping, inspecting, or logging errors in your Go code, following the rules for lowercase error strings, %w wrapping, chain inspection, and single-handling (return-only or log-only) at each layer.

Frequently Asked Questions about golang-error-handling

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

FAQPage Schema
When should I use errors.Join for independent failures in Go?

Use errors.Join to combine independent golang failures cleanly. It aggregates multiple errors into a single chain, allowing errors.Is and errors.As to traverse all joined failures without discarding any context.

How does slog work with structured logging for HTTP services in Go?

The single handling rule dictates that Go errors must be either logged or returned, never both. This prevents duplicate noise and swallowed failures, ensuring reliable inspection and clean log aggregation at scale.

Does samber/oops work with Go error handling to add stack traces?

Use slog for structured logging in Go HTTP services by applying low-cardinality messages and structured attributes. This maintains useful log aggregation at scale and pairs effectively with error wrapping in middleware chains.

When should I not use panic and recover for Go error handling?

Use samber/oops for production Go error handling to add stack traces and structured context. It integrates with error wrapping practices to provide detailed debugging insights without leaking sensitive details to end users.

Why does my Go error wrapping create duplicate noise in logs?

Use sentinel errors in Go to model expected conditions and custom error types to carry structured data. Both support errors.Is and errors.As inspection, maintaining traversable chains across layers.