golang-error-handling

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

Updated May 28, 2026
One-click install
npx skills add https://github.com/vanstinator/semantic-search --skill golang-error-handling-vanstinator
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-error-handling
Source: https://github.com/vanstinator/semantic-search/tree/main/.agents/skills/golang-error-handling
Command: npx skills add https://github.com/vanstinator/semantic-search --skill golang-error-handling-vanstinator

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires errors, fmt, slog, samber/oops, and includes references (resource) components.

What problem does it solve?

Prevents fragile, noisy, and un-debuggable Go error handling by enforcing idiomatic wrapping, inspection, and single-handling (log OR return) rules with production-friendly structured logging.

Core Features & Use Cases

  • Idiomatic wrapping and inspection: Uses fmt.Errorf with %w and enforces errors.Is/errors.As (and errors.Join) so callers can reliably match and extract errors through chains.
  • Operationally safe logging: Encourages structured slog logging and low-cardinality messages, moving variable details into attributes and samber/oops where appropriate.
  • Audit-friendly modes: Supports coding, PR review, and large codebase auditing with focused checks for swallowed errors, missing context, and panic misuse.

Quick Start

Ask an AI coding agent to apply this skill to your Go changes by checking that every returned error is handled once, wrapped with contextual %w, uses lowercase error strings, and logs errors only at the chosen boundary with slog/samber/oops where required.

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 Go errors using errors.Is and errors.As?

Idiomatic Go error handling uses fmt.Errorf with %w to chain errors so callers can reliably match and extract them using errors.Is and errors.As through the wrapping chain.

What is the best way to log Go errors without losing context?

The best way to log Go errors is using structured slog logging with low-cardinality messages, moving variable details into attributes to maintain context and reduce noise.

How do I wrap errors in Go without duplicating log messages?

To wrap errors in Go without duplicating logs, apply the single-handling rule: log OR return the error, wrapping it with contextual %w and logging only at the chosen boundary.

Can I use samber/oops for structured error handling in Go?

Yes, you can use samber/oops for structured Go error handling, moving variable details into attributes where appropriate alongside slog for production-friendly logging.

Does this Go error handling approach work for PR reviews and codebase audits?

Yes, this Go error handling approach supports audit-friendly modes for PR review and large codebase auditing, checking for swallowed errors, missing context, and panic misuse.

Why should I use lowercase error strings in Go?

You should use lowercase error strings in Go to maintain idiomatic consistency across error wrapping chains, preventing capitalization issues when errors are combined or logged at boundaries.