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.