go-samber-oops

Implements structured error handling in Go using the samber/oops builder pattern.

1|2|Updated Nov 25, 2017
One-click install
npx skills add https://github.com/asarchami/dotfiles --skill go-samber-oops-asarchami
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: go-samber-oops
Source: https://github.com/asarchami/dotfiles/tree/main/dot_claude/skills/go-samber-oops
Command: npx skills add https://github.com/asarchami/dotfiles --skill go-samber-oops-asarchami

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Standard Go errors lack context — you see "connection failed" but not which user triggered it, what query was running, or the full call stack. This Skill guides you to write errors as structured data with samber/oops, so every error carries domain, attributes, trace IDs, and stack traces for on-call diagnosis. ## Core Features & Use Cases - Error Builder Chains: Compose errors fluently with .In(), .Tags(), .Code(), .With(), .User(), and .Tenant() to attach structured context at every layer. - Wrapping & Panic Recovery: Wrap existing errors with .Wrapf() (nil-safe), and convert panics to structured errors with .Recover() at goroutine boundaries. - Low-Cardinality Messages: Keep variable data in .With() attributes instead of message strings so APM tools like Datadog, Loki, and Sentry can group errors properly. - Use Case: In a repository layer, wrap a failed database query with the SQL statement, user ID, and domain tags; in the HTTP handler, add the request and trace ID — producing one error with full diagnostic context. ## Quick Start Refactor this Go function to use samber/oops structured errors with domain, tags, and attributes instead of plain fmt.Errorf.

Frequently Asked Questions about go-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 with samber/oops?

Use the fluent builder pattern: chain methods like oops.In("domain").Tags("database").With("key", value) and terminate with .Errorf(), .Wrap(err), or .Wrapf(). Attributes travel with the error through the call stack.

How to wrap errors in Go without nil checks?

Call oops.Wrapf(err, "message") directly — it returns nil if err is nil, so no explicit nil check is needed. Add context at each architectural layer, at least once per package boundary.

samber/oops vs standard Go errors — what is the difference?

Standard Go errors carry only a message string. samber/oops is a drop-in replacement adding structured attributes, stack traces, machine-readable codes, public user-safe messages, and trace IDs, while still implementing the standard error interface.

Does samber/oops work with slog and other loggers?

Yes. oops errors marshal to JSON and work with any logger. Use slog.Error(err.Error(), slog.Any("error", err)), or formatters for zerolog and logrus, extracting fields via the OopsError interface methods.

Why should error messages avoid variable data in samber/oops?

Interpolating values like user IDs into messages creates high-cardinality strings that break error grouping in APM tools such as Datadog, Loki, and Sentry. Put variable data in .With() attributes and keep messages static.

How do I recover from panics with samber/oops?

Use oops.Recover(fn) or .Recoverf() at goroutine boundaries to convert panics into structured errors. Chain context first, e.g. oops.In("worker").Code("panic_recovered").Recover(func() { riskyCall() }).