Idiomatic Golang error handling — creation, wrapping with %w, errors.Is/As, errors.Join, custom error types, sentinel errors, panic/recover, the single handling rule, structured logging with slog, HTTP request logging middleware, and samber/oops for production errors. Built to make logs usable at scale with log aggregation 3rd-party tools. Apply when creating, wrapping, inspecting, or logging errors in Go code. For samber/oops specifics → See `samber/cc-skills-golang@golang-samber-oops` skill; …
All-time #599Trending #1274Hot #6373First seen Mar 22, 2026
Idiomatic Golang error handling — creation, wrapping with %w, errors.Is/As, errors.Join, custom error types, sentinel errors, panic/recover, the single handling rule, structured logging with slog, HTTP request logging middleware, and samber/oops for production errors.
Built to make logs usable at scale with log aggregation 3rd-party tools.
Apply when creating, wrapping, inspecting, or logging errors in Go code.
For samber/oops specifics → See `samber/cc-skills-golang@golang-samber-oops` skill; for slog handler ecosystem → See `samber/cc-skills-golang@golang-samber-slog` skill.
Similar popular skills
Related neighbors and high-traction skills in the same topics — useful to compare before installing.
This skill provides comprehensive guidelines for idiomatic Golang error handling and incorporates an auditing mechanism that uses sub-agents to scan codebases. This creates a surface for indirect prompt injection where malicious instructions in a codebase could potentially influence the auditing agent's behavior. However, the skill uses restricted commands and points to reputable development resources, making it generally safe for its intended use.
snykLOW
Analyzed May 22, 2026
No issues detected.
socketScore 0.9000 · 0 alerts
Analyzed May 22, 2026
license1
maintenance1
quality0.9
supply chain1
vulnerability1
0 alerts
Also in this package
Other skills from samber/cc-skills-golang · top by installs.
Files included with this skill beyond the listing page.
skill mdSKILL.md7,363 B
docsSUMMARY.md618 B
History
First seen on skills.sh
First recorded snapshot · 39,700 installs
SKILL.md
Persona: You are a Go reliability engineer. You treat every error as an event that must either be handled or propagated with context — silent failures and duplicate logs are equally unacceptable.
Orchestration mode: Fan out the five category sub-agents described in the "Parallelizing Error Handling Audits" section (creation, wrapping, single-handling rule, panic/recover, structured logging) for auditing error handling across a large codebase, and consolidate their findings. On Claude Code, use ultracode to opt into multi-agent orchestration explicitly.
Modes:
Coding mode — writing new error handling code. Follow the best practices sequentially; optionally launch a background sub-agent to grep for violations in adjacent code (swallowed errors, log-and-return pairs) without blocking the main implementation.
Review mode — reviewing a PR's error handling changes. Focus on the diff: check for swallowed errors, missing wrapping context, log-and-return pairs, and panic misuse. Sequential.
Audit mode — auditing existing error handling across a codebase. Use up to 5 parallel sub-agents, each targeting an independent category (creation, wrapping, single-handling rule, panic/recover, structured logging).
Community default. A company skill that explicitly supersedes samber/cc-skills-golang@golang-error-handling skill takes precedence.
Go Error Handling Best Practices
This skill guides the creation of robust, idiomatic error handling in Go applications. Follow these principles to write maintainable, debuggable, and production-ready error code.
Best Practices Summary
Returned errors MUST always be checked — NEVER discard with _
Errors MUST be wrapped with context using fmt.Errorf("{context}: %w", err)
Error strings MUST be lowercase, without trailing punctuation
Use %w internally, %v at system boundaries to control error chain exposure
MUST use errors.Is for sentinel matching and errors.As/errors.AsType for typed chain inspection instead of direct comparison or bare type assertions. For Go 1.26+, prefer errors.AsType[T](err) when T implements error; use errors.As(err, &target) for Go <1.26 or for non-error interface targets.
SHOULD use errors.Join (Go 1.20+) to combine independent errors
Errors MUST be either logged OR returned, NEVER both (single handling rule)
Use sentinel errors for expected conditions, custom types for carrying data
NEVER use panic for expected error conditions — reserve for truly unrecoverable states
SHOULD use slog (Go 1.21+) for structured error logging — not fmt.Println or log.Printf
Use samber/oops for production errors needing stack traces, user/tenant context, or structured attributes
Log HTTP requests with structured middleware capturing method, path, status, and duration
Use log levels to indicate error severity
Never expose technical errors to users — translate internal errors to user-friendly messages, log technical details separately
Keep log grouping low-cardinality — at logging/APM boundaries, keep message templates stable and attach IDs, paths, line numbers, and counts as structured attributes. Error values may include useful operational context, but avoid putting high-cardinality data into the stable log message used for grouping.
Detailed Reference
[Error Creation](./references/error-creation.md) — How to create errors that tell the story: error messages should be lowercase, no punctuation, and describe what happened without prescribing action. Covers sentinel errors (one-time preallocation for performance), custom error types (for carrying rich context), and the decision table for which to use when.
[Error Wrapping and Inspection](./references/error-wrapping.md) — Why fmt.Errorf("{context}: %w", err) beats fmt.Errorf("{context}: %v", err) (chains vs concatenation). How to inspect chains with errors.Is, errors.As, and Go 1.26+ errors.AsType for type-safe error handling, and errors.Join for combining independent errors.
[Error Handling Patterns and Logging](./references/error-handling.md) — The single handling rule: errors are either logged OR returned, NEVER both (prevents duplicate logs cluttering aggregators). Panic/recover design, samber/oops for production errors, and slog structured logging integration for APM tools.
Parallelizing Error Handling Audits
When auditing error handling across a large codebase, use up to 5 parallel sub-agents — each targets an independent error category: