| name | golang-error-handling |
| description | 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. |
| user-invocable | true |
| license | MIT |
| compatibility | Designed for Claude Code or similar AI coding agents, and for projects using Golang. |
| metadata | {"author":"samber","version":"1.1.2","openclaw":{"emoji":"โ ๏ธ","homepage":"https://github.com/samber/cc-skills-golang","requires":{"bins":"[Truncated]"},"install":[]}} |
| allowed-tools | Read Edit Write Glob Grep Bash(go:*) Bash(golangci-lint:*) Bash(git:*) Agent |
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
- 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 and errors.As instead of direct comparison or type assertion
- 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