Now liveThe Skillselion MCP - thousands of ranked skills, loaded into your agent mid-task. No install.Get it →
samber avatar

Golang Error Handling

  • 35.5k installs
  • 2.8k repo stars
  • Updated July 27, 2026
  • samber/cc-skills-golang

Golang-error-handling is a code-review skill for idiomatic error creation, wrapping, inspection, and production logging.

About

Go error handling skill covering idiomatic error creation, wrapping with context, inspection patterns, and production logging. Teaches the single handling rule (log or return, not both), sentinel errors, custom error types, panic/recover design, and structured logging with slog.

  • Error wrapping with %w for chain inspection via errors.Is/As
  • Single handling rule: errors logged OR returned, never both
  • Structured logging with slog and samber/oops for production errors

Golang Error Handling by the numbers

  • 35,470 all-time installs (skills.sh)
  • +685 installs in the week ending Jul 28, 2026 (Skillselion tracking)
  • Ranked #11 of 1,382 Code Review & Quality skills by installs in the Skillselion catalog
  • Security screen: LOW risk (skills.sh audit)
  • Data as of Jul 28, 2026 (Skillselion catalog sync)
npx skills add https://github.com/samber/cc-skills-golang --skill golang-error-handling

Add your badge

Show developers this skill is listed on Skillselion. Paste this into your README.

Listed on Skillselion
Installs35.5k
repo stars2.8k
Security audit3 / 3 scanners passed
Last updatedJuly 27, 2026
Repositorysamber/cc-skills-golang

How do you handle errors in Go HTTP middleware?

Implement robust, debuggable error handling that prevents duplicate logs and maintains error chains.

Who is it for?

Go backend engineers building HTTP APIs who need agents to use slog, propagate middleware errors, and avoid log-and-return anti-patterns.

Skip if: Frontend-only projects or Go CLIs that do not use HTTP middleware chains and structured service logging.

When should I use this skill?

The user writes Go HTTP handlers, middleware, or service error handling and needs slog-based structured logging patterns.

What you get

Go middleware chains with slog structured logging, propagated errors, and traceable request-flow logs.

  • Go middleware with slog logging
  • error-propagating handler chains

By the numbers

  • Eval tests a 3-middleware HTTP chain: Logging, Auth, and RateLimit

Files

SKILL.mdMarkdownGitHub ↗

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.AsType[T](err) 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. Use sentinel errors for expected conditions, custom types for carrying data 9. NEVER use `panic` for expected error conditions — reserve for truly unrecoverable states 10. SHOULD use `slog` (Go 1.21+) for structured error logging — not fmt.Println or log.Printf 11. Use `samber/oops` for production errors needing stack traces, user/tenant context, or structured attributes 12. Log HTTP requests with structured middleware capturing method, path, status, and duration 13. Use log levels to indicate error severity 14. Never expose technical errors to users — translate internal errors to user-friendly messages, log technical details separately 15. 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 (via the Agent tool) — each targets an independent error category:

  • Sub-agent 1: Error creation — validate errors.New/fmt.Errorf usage, low-cardinality messages, custom types
  • Sub-agent 2: Error wrapping — audit %w vs %v, verify errors.Is/errors.As patterns
  • Sub-agent 3: Single handling rule — find log-and-return violations, swallowed errors, discarded errors (_)
  • Sub-agent 4: Panic/recover — audit panic usage, verify recovery at goroutine boundaries
  • Sub-agent 5: Structured logging — verify slog usage at error sites, check for PII in error messages

Cross-References

  • → See samber/cc-skills-golang@golang-samber-oops for full samber/oops API, builder patterns, and logger integration
  • → See samber/cc-skills-golang@golang-observability for structured logging setup, log levels, and request logging middleware
  • → See samber/cc-skills-golang@golang-safety for nil interface trap and nil error comparison pitfalls
  • → See samber/cc-skills-golang@golang-naming for error naming conventions (ErrNotFound, PathError)
  • → See samber/cc-skills-golang@golang-continuous-integration skill for automated AI-driven code review in CI using these guidelines

References

Related skills

How it compares

Pick golang-error-handling over generic Go lint skills when middleware error propagation and slog structured logging are the primary concerns.

FAQ

Which Go logging package does golang-error-handling require?

golang-error-handling requires slog for structured logging in Go HTTP services and explicitly rejects log.Printf patterns, with eval assertions verifying slog usage across middleware layers.

What middleware anti-patterns does golang-error-handling catch?

golang-error-handling catches log-and-return violations and high-cardinality error messages with interpolated IPs or rate limits in Go HTTP middleware chains with Logging, Auth, and RateLimit layers.

Is Golang Error Handling safe to install?

skills.sh reports 3 of 3 security scanners passed. Review the Security Audits panel on this page before installing in production.

Code Review & Qualitybackendtesting

This week in AI coding

Five minutes, every Monday - the tools, releases and tactics for developers.

unsubscribe anytime.