golang-error-handling

Enforce idiomatic Go error handling with wrapping, inspection, and structured logging.

1|Updated Apr 4, 2026
One-click install
npx skills add https://github.com/Jylhis/claude-marketplace --skill golang-error-handling-jylhis
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-error-handling
Source: https://github.com/Jylhis/claude-marketplace/tree/main/plugins/golang-dev/skills/golang-error-handling
Command: npx skills add https://github.com/Jylhis/claude-marketplace --skill golang-error-handling-jylhis

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This skill enables Go developers to implement robust, idiomatic error handling by standardizing creation, wrapping, inspection, and logging across codebases.

Core Features & Use Cases

  • Sentinel errors and custom error types with rich context
  • Follow errors.Is / errors.As for safe error inspection
  • Use errors.Join to combine independent errors
  • Structured logging with slog and samber/oops for production-grade errors
  • Consistent middleware patterns for HTTP request logging and the single handling rule (log versus return)

Quick Start

Adopt the recommended error-handling patterns across your Go codebase to start wrapping errors with context and using structured logging.

Frequently Asked Questions about golang-error-handling

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I handle errors in Go with slog and structured logging?

Idiomatic Go error handling with slog uses structured logging to capture rich context. You wrap errors with %w and log them at system boundaries using %v, enforcing a single handling rule to either log or return.

What is the best way to wrap Go errors with context using errors.Is and errors.As?

The best way to wrap Go errors is using %w to add context. Use errors.Is to check for specific sentinel values and errors.As to extract custom error types, ensuring safe inspection across all application layers.

How do I combine independent Go errors together?

You can combine independent Go errors using errors.Join. This function aggregates multiple errors into a single error value, which is useful when collecting validation failures or concurrent operation errors.

Can I use samber/oops with Go middleware for HTTP request logging?

Yes, samber/oops integrates with Go middleware for HTTP request logging. It enforces consistent middleware patterns by applying structured logging and the single handling rule to log versus return errors across HTTP boundaries.

When should I use %w versus %v for Go error wrapping?

Use %w for Go error wrapping to maintain the error chain for inspection via errors.Is and errors.As. Use %v at system boundaries to format the error as a string when returning to external clients.