golang-samber-oops

Structure Go errors with samber/oops using fluent builder chains and panic recovery.

2|Updated Mar 13, 2023
One-click install
npx skills add https://github.com/haipham22/golang-sample --skill golang-samber-oops-haipham22
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-samber-oops
Source: https://github.com/haipham22/golang-sample/tree/main/.agents/skills/golang-samber-oops
Command: npx skills add https://github.com/haipham22/golang-sample --skill golang-samber-oops-haipham22

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill helps Go developers turn plain errors and panics into structured, diagnosable failures with rich context, safer user-facing messages, and better observability across application layers.

Core Features & Use Cases

  • Structured error building: Create fluent error chains with domain, tags, codes, attributes, user context, and tenant context.
  • Layered diagnostics: Add context at handler, service, and repository boundaries so the full failure path is preserved.
  • Safe public messaging: Separate technical details from user-safe messages, then retrieve the public message when responding to clients.
  • Panic recovery and context propagation: Convert panics to errors with recovery helpers and carry preconfigured error context through Go contexts.
  • Use case: A Go API can use this Skill to report an out-of-stock purchase with a stable error code, request metadata, and a friendly frontend message while keeping internal details in logs.

Quick Start

Use the golang-samber-oops skill to rewrite the Go function so it returns structured errors with context, a stable public message, and panic recovery.

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 Golang errors across API layers?

You can add structured context to Golang errors by building fluent error chains with domain, tags, codes, and attributes at handler, service, and repository boundaries. This preserves the full failure path for layered diagnostics across your application.

What is the best way to separate internal error details from user-safe messages in Go?

Separating internal error details from user-safe messages in Go involves defining a stable public message during error creation. You then retrieve this specific public message when responding to clients, keeping technical diagnostics isolated in internal logs.

Can I convert Go panics into structured errors with context propagation?

Yes, you can convert Go panics into structured errors using recovery helpers. These helpers capture the panic and wrap it into a structured error, while allowing you to carry preconfigured error context through Go contexts for better observability.

How do I track tenant and user context in Golang structured logging?

You can track tenant and user context in Golang structured logging by attaching user and tenant context fields directly to your structured errors. This contextual data propagates through your application layers and appears in observable diagnostics.

Does this structured error handling approach work for goroutines in Go?

Yes, this structured error handling approach works for goroutines in Go. It provides panic recovery helpers and context propagation specifically designed to capture failures and carry preconfigured diagnostic context safely across concurrent operations.

When should I use structured errors with error codes instead of plain Go errors?

You should use structured errors with error codes instead of plain Go errors when you need observable diagnostics, layered context, or stable client-facing messages. This is critical for APIs requiring consistent error reporting and detailed internal tracing.