Agent skill · software engineering · aiskillstore
golang-error-handling
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.
Why this skill is useful
Adds detailed error handling practices and logging strategies specific to Go, including custom error types and structured logging scripts that enhance the AI's capabilities in Go development.
What it needs
Requires go installed locally. About 3k tokens when loaded. Last updated 2026-08-07. 405 stars on the source repository.
What this skill does
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. 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 1. Returned errors MUST always be checked — NEVER discard with 2. Errors MUST be wrapped with context using fmt.Errorf("{context}: %w", err) 3. Error strings MUST be lowercase, without trailing punctuation 4. Use %w internally, %v at system boundaries to control error chain exposure 5. 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.AsTypeT when T implements error; use errors.As(err, &target) for Go <1.26 or for non-error interface targets. 6. SHOULD use errors.Join (Go 1.20+) to combine independent errors 7. Errors MUST be either logged OR returned, NEVER both (single handling rule) 8. …
How to use it
Reference it in AdaL, Claude Code, Cursor or any coding agent — nothing to install:
@skills aiskillstore/golang-error-handling