# golang-error-handling

> Claude/Codex skill by [@samber](https://omgskills.com/library/samber/index.md) · 3.7k stars · Updated 2026-10-23

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.

Tags: agent, agent-skills, ai, antigravity, claude, claude-code, code, codex, coding, copilot, cursor, gemini, gemini-cli-extension, openclaw, opencode, plugin, skills, skillsmp, vibe-coding

## Install

```sh
git clone https://github.com/samber/cc-skills-golang /tmp/cc-skills-golang && ln -s /tmp/cc-skills-golang/skills/golang-error-handling ~/.claude/skills/golang-error-handling
```

## From README

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.AsTypeT when T implements error; use errors.As(err, &target) for Go \<1.26 or for non-error interface targets.

## Links

- HTML page: https://omgskills.com/library/samber/cc-skills-golang/golang-error-handling/
- GitHub: https://github.com/samber/cc-skills-golang
- Author: [@samber](https://omgskills.com/library/samber/index.md)

## More from this repo

- [golang-benchmark](https://omgskills.com/library/samber/cc-skills-golang/golang-benchmark/index.md) — Golang benchmarking, profiling, and performance measurement.
   - [@samber](https://omgskills.com/library/samber/index.md) · 3.7k stars
- [golang-cli](https://omgskills.com/library/samber/cc-skills-golang/golang-cli/index.md) — Golang CLI application development.
   - [@samber](https://omgskills.com/library/samber/index.md) · 3.7k stars
- [golang-code-style](https://omgskills.com/library/samber/cc-skills-golang/golang-code-style/index.md) — Golang code style conventions — line length and breaking, variable declarations, control flow clarity, when comments...
   - [@samber](https://omgskills.com/library/samber/index.md) · 3.7k stars
