golang-error-handling

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

Updated Apr 24, 2026
One-click install
npx skills add https://github.com/Utchash007/TermTales --skill golang-error-handling-utchash007
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-error-handling
Source: https://github.com/Utchash007/TermTales/tree/main/.agents/skills/golang-error-handling
Command: npx skills add https://github.com/Utchash007/TermTales --skill golang-error-handling-utchash007

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This skill codifies idiomatic Go error handling practices to ensure errors are created with meaningful, low-cardinality messages, wrapped with context, and propagated through the chain for proper inspection and observability.

Core Features & Use Cases

  • Returned errors MUST be checked and wrapped with context using %w
  • Use errors.Is/errors.As and errors.Join to compose and inspect error chains
  • Promote structured logging with slog and samber/oops for production errors
  • Apply the single handling rule to avoid duplicate logs and ensure clear user-facing messages

Quick Start

Refactor a sample Go function to wrap errors with context using %w and propagate them with errors.Is/As.

Frequently Asked Questions about golang-error-handling

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

FAQPage Schema
What is the best way to wrap Go errors with context across service layers?

To wrap Go errors with context, use the %w verb when returning errors to preserve the original chain. This allows errors.Is and errors.As to inspect the root cause while logging the added context via slog.

How do I avoid duplicate error logs in Go services?

Avoid duplicate error logs in Go by applying the single handling rule, which ensures errors are logged only once at the boundary layer to produce clear user-facing messages without redundant entries.

How does errors.Join work for composing Go error chains?

errors.Join composes Go error chains by combining multiple errors into a single value. This allows errors.Is and errors.As to inspect all joined errors simultaneously during propagation and testing.

Can I use slog for structured logging of Go errors?

Yes, slog supports structured logging of Go errors by pairing context-rich logs with wrapped errors. This promotes consistent observability and satisfies production error tracking requirements.

Does samber/oops work with standard Go error wrapping?

samber/oops works with standard Go error wrapping by extending %w and errors.Is patterns. It provides structured logging capabilities that integrate with idiomatic error chains for enhanced observability.

When should I use errors.As instead of errors.Is in Go?

Use errors.As in Go when you need to access a specific typed error's fields, whereas errors.Is only checks if an error matches a sentinel value. Both inspect wrapped error chains effectively.