golang-error-handling

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

5|1|Updated Apr 14, 2026
One-click install
npx skills add https://github.com/omarluq/og-template --skill golang-error-handling-omarluq
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-error-handling
Source: https://github.com/omarluq/og-template/tree/main/.agents/skills/golang-error-handling
Command: npx skills add https://github.com/omarluq/og-template --skill golang-error-handling-omarluq

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Go errors are easy to mismanage; this skill enforces idiomatic patterns and provides a usable blueprint for safe propagation, wrapping, and structured logging.

Core Features & Use Cases

  • Creation and sentinel types with stable error messages
  • Wrapping and inspection with errors.Is/As and errors.Join
  • Panic/recover guidelines and use of samber/oops for production errors
  • Structured logging via slog and contextual attributes
  • HTTP request logging middleware patterns and central error handling

Quick Start

Show an idiomatic Go error-handling example using creation, wrapping, inspection, and logging with slog and samber/oops.

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 in Go using fmt.Errorf and inspect them with errors.Is?

Wrap Go errors using fmt.Errorf with the %w verb to preserve the original error chain, then inspect the hierarchy with errors.Is or errors.As to match sentinel values and extract structured types for robust error propagation.

What's the best way to handle structured logging of Go errors across layered services?

Structured logging of Go errors across layered services is handled using slog and samber/oops to attach contextual attributes, enabling central error handling and HTTP request logging middleware to trace error propagation through layers.

How do I combine multiple Go errors using errors.Join?

Combine multiple Go errors using errors.Join to aggregate failures into a single error value, allowing you to inspect individual wrapped errors with errors.Is and log the collected context via slog for observable debugging.

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

Yes, samber/oops integrates with slog for idiomatic Go error handling by wrapping errors with contextual attributes that slog consumes, allowing production errors to carry traceable context through HTTP request logging middleware.

How do I create and use sentinel error types with stable messages in Go?

Create sentinel error types in Go using stable error messages and var declarations, then match them throughout your service layers using errors.Is to ensure consistent error inspection and propagation across handlers and middleware.

When should I use panic and recover for Go error handling instead of returning errors?

Use panic and recover for Go error handling only for truly unrecoverable program states, not routine control flow; idiomatic Go error handling requires returning wrapped errors with fmt.Errorf and propagating them through service layers.