golang-error-handling

Standardize Go error handling with wrapping, errors.Is/As, and slog logging.

Updated Mar 29, 2026
One-click install
npx skills add https://github.com/osmanozen/go-commerce --skill golang-error-handling-osmanozen
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: golang-error-handling
Source: https://github.com/osmanozen/go-commerce/tree/main/.agents/skills/golang-error-handling
Command: npx skills add https://github.com/osmanozen/go-commerce --skill golang-error-handling-osmanozen

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Go projects often suffer from inconsistent and unsafe error handling. This skill standardizes how errors are created, wrapped with context, inspected with errors.Is/As, and logged, improving debugging and reliability.

Core Features & Use Cases

  • Ensures errors are checked and wrapped with context using %w
  • Promotes the single handling rule, structured logging with slog, and production-ready patterns with samber/oops
  • Applies across services to build traceable error flows and robust failure handling
  • Example: an HTTP handler wraps an error with context instead of logging and returning at the same layer

Quick Start

Apply idiomatic Go error handling by wrapping errors with context and using structured logging across services.

Frequently Asked Questions about golang-error-handling

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

FAQPage Schema
How do I wrap errors with context in Go using fmt.Errorf?▼

Apply the single handling rule: return the error once with context using %w, and log it only at the boundary layer using slog to avoid duplicate logs and lost stack context across modules.

How do errors.Is and errors.As work for inspecting wrapped errors?▼

errors.Is checks if an error matches a target sentinel value, while errors.As extracts a specific error type, allowing deterministic inspection of wrapped errors for robust failure handling.

Does samber/oops work with slog for structured Go error handling?▼

Yes, samber/oops integrates with slog to provide structured context for errors, enabling production-ready logging patterns and traceable error flows across Go services without panicking for expected errors.

What is the best way to avoid duplicate error logging in Go services?▼

Apply the single handling rule: return the error once with context using %w, and log it only at the boundary layer using slog to avoid duplicate logs and lost stack context across modules.

Should I use panic for expected errors in Go HTTP handlers?▼

Avoid panic for expected errors in Go HTTP handlers; instead, wrap the error with context using fmt.Errorf and %w, then return it to the caller for deterministic logging and robust failure handling.