Back to Skills

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.

1,714stars111forksUpdated 5/18/2026

Security Assessment

Safe(100/100)
Security Score100/100

About golang-error-handling

The `golang-error-handling` skill is designed to enforce idiomatic and robust error handling practices in Go applications. It addresses common challenges in Go development where errors can be silently ignored, improperly wrapped, or inconsistently logged, which complicates debugging and monitoring in production systems. By guiding developers through best practices for error creation, wrapping, inspection, and logging, this skill ensures that errors are consistently handled, providing clarity and reliability in Go codebases.

This skill offers a comprehensive set of features to manage Go errors effectively. It covers error creation, wrapping with `%w`, and inspection using `errors.Is` and `errors.As`. It supports combining errors with `errors.Join`, creating custom error types, using sentinel errors for expected conditions, and adhering to the single handling rule to avoid duplicate logging. For logging, it integrates structured logging with `slog` and provides middleware for HTTP request logging. It also leverages `samber/oops` for production-grade error reporting, including stack traces and structured attributes. Additionally, it guides safe use of `panic` and `recover`, ensuring unrecoverable conditions are handled appropriately.

This skill is intended for Go developers, reliability engineers, and teams responsible for maintaining high-quality, production-ready Go applications. It is particularly useful in scenarios where consistent error handling, structured logging, and observability are critical, such as web services, APIs, and systems monitored via APM or log aggregation tools. By applying this skill, users can minimize silent failures, reduce debugging complexity, and produce maintainable, scalable Go applications that integrate seamlessly with modern monitoring and logging infrastructures.

FAQ

How do I apply this skill in my Go project?

You can invoke the skill in coding, review, or audit mode to guide the creation, inspection, and logging of errors according to best practices outlined in the documentation. Follow the principles for returned errors, wrapping, logging, and structured error handling.

Is this skill compatible with all Go versions?

The skill is designed for projects using Golang and supports features introduced in Go 1.20+ (`errors.Join`) and Go 1.21+ (`slog`). Ensure your Go version meets these requirements for full functionality.

Can I use this skill with other AI coding agents?

Yes, it is compatible with Claude Code or similar AI coding agents capable of executing Go code and assisting with code reviews, audits, and error handling guidance.

Does the skill enforce logging practices?

Yes, it recommends structured logging with `slog` or `samber/oops`, guides HTTP request logging, and advises keeping error messages low-cardinality to facilitate aggregation and observability without exposing sensitive details to users.

Are there limitations regarding panic usage?

The skill strictly advises against using `panic` for expected errors, reserving it only for truly unrecoverable conditions, and ensures that proper `recover` handling is applied where needed.

All Files

5 files
evals/evals.json14.5 KB
View
references/error-creation.md4.8 KB
View
SKILL.md6.4 KB
View
references/error-handling.md4.1 KB
View
references/error-wrapping.md2.9 KB
View

Install golang-error-handling

Download and extract the skill files to your .claude/skills/ directory.

Quick Setup:

  1. Copy the skill folder to .claude/skills/
  2. Claude will automatically detect and use the skill