golang-error-handling

Standardize Go error creation, wrapping, inspection, and logging with slog.

7|1|Updated Mar 15, 2026
One-click install
npx skills add https://github.com/Harmeet10000/skills --skill golang-error-handling-harmeet10000
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-error-handling
Source: https://github.com/Harmeet10000/skills/tree/main/skills/backend/Golang/golang-error-handling
Command: npx skills add https://github.com/Harmeet10000/skills --skill golang-error-handling-harmeet10000

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Go projects often suffer from inconsistent error handling patterns, leading to opaque failures and poor debuggability. This Skill standardizes creation, wrapping, inspection, and logging to help you write reliable, observable Go code.

Core Features & Use Cases

  • Idiomatic error creation, including sentinel errors and custom error types.
  • Wrapping with %w and using errors.Is / errors.As to inspect error chains.
  • Using errors.Join to combine independent errors and structured logging with slog and samber/oops for production-grade errors.
  • Panic/recover guidance and a dedicated HTTP request logging middleware.
  • Production-ready patterns that improve debuggability and observability at scale.

Quick Start

Read and apply the Go error-handling best practices to your codebase to improve reliability and observability.

Frequently Asked Questions about golang-error-handling

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

FAQPage Schema
How do I standardize Go error handling and wrapping for production?

Standardize Go error handling by applying a single rule: log or return. Use sentinel errors, custom types, %w wrapping, and errors.Is/As for inspection to achieve production-grade observability.

What is the best way to add context to Go errors before logging?

Add context to Go errors by wrapping them with samber/oops. This enriches errors with structured metadata before logging with slog, improving debuggability and traceability in production.

How does errors.Join work for combining independent Go errors?

errors.Join combines multiple independent Go errors into a single error chain. You then inspect the combined result using errors.Is and errors.As to handle specific failure conditions accurately.

When should I use panic and recover for error handling in Go?

Use panic and recover in Go for truly exceptional, unrecoverable failures rather than routine errors. The Skill provides specific guidance on applying panic/recover safely without compromising application stability.

How do I implement HTTP request logging middleware with slog in Go?

Implement HTTP request logging middleware in Go using slog for structured output. The Skill provides a dedicated middleware component that standardizes request observability and integrates with the error handling rules.