golang-samber-oops

Implement structured Go error handling with samber/oops builder patterns.

2.9k|191|Updated Mar 21, 2026
One-click install
npx skills add https://github.com/samber/cc-skills-golang --skill golang-samber-oops
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-samber-oops
Source: https://github.com/samber/cc-skills-golang/tree/main/skills/golang-samber-oops
Command: npx skills add https://github.com/samber/cc-skills-golang --skill golang-samber-oops

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Go developers often struggle with errors that lack context, making debugging and incident response slow. samber/oops provides a fluent builder to attach domain, error codes, user-facing messages, and structured attributes so errors travel with rich context across service boundaries.

Core Features & Use Cases

  • Structured context via .In(), .With(), .User(), .Tenant(), and .Wrapf() to preserve context as errors propagate.
  • Stack traces, machine-readable codes, and a public vs technical message system to improve observability and user experience.
  • Context propagation with WithBuilder/FromContext and Recover to convert panics into well-formed errors.
  • Per-layer context enrichment (handler/service/repository) with targeted attributes and tagging.

Quick Start

Build an oops error with In("service"), With("operation","checkout"), and Wrapf(err, "operation failed") to propagate rich context.

Frequently Asked Questions about golang-samber-oops

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

FAQPage Schema
How do I add structured context to Go errors across service boundaries?

To add structured context to Go errors, use a fluent builder pattern with methods like In, With, User, and Tenant to attach domain attributes and stack traces. This ensures errors travel with rich context across HTTP handlers, services, and repositories.

What is the best way to propagate error details through Go context?

Propagating error details through Go context is best achieved using WithBuilder and FromContext. This mechanism preserves builder attributes and traces as errors cross service boundaries, ensuring robust observability and low-cardinality error tracking during incident response.

Can I convert Go panics into structured errors automatically?

You can convert Go panics into structured errors automatically by using the Recover function. This safely captures panics and transforms them into well-formed, machine-readable errors enriched with domain context and stack traces for debugging.

How do I separate public user-facing messages from technical error traces in Go?

To separate public user-facing messages from technical traces in Go, use the Public and Code builder methods. Public sets a safe message for users, while Code and Wrapf attach machine-readable tags and technical context for backend observability.

Does structured error handling work for multi-layer Go applications?

Structured error handling works effectively for multi-layer Go applications by applying per-layer context enrichment. Handlers, services, and repositories can each append targeted attributes using Wrapf and With, producing robust traces without losing upstream context.