What problem does it solve?
samber/oops converts unstructured Go errors into structured, diagnosable error objects that carry domain context, stack traces, machine-readable codes, user-safe public messages, and rich attributes for observability.
Core Features & Use Cases
- Structured error context: Attach key-value attributes via With/Tags/In and use WithContext to extract values from Go context.
- Fluent error builder chain: Build errors with a composable pattern and wrap existing errors to preserve original causes.
- Operational observability: Ensure low-cardinality messages for clean grouping in APM/logging systems, while variable data is stored as attributes.
- Layered error handling: Add context at package boundaries (HTTP handler → service → repository) using Wrap/Wrapf and appropriate domain/tag information.
- Panic recovery in goroutines: Convert panics into structured errors using oops.Recover or builder .Recover at goroutine boundaries.
- Public vs technical messages: Provide a user-safe public message using .Public and keep technical details in Errorf/Wrapf.
- Logger integration: Extract fields (Code, Domain, Tags, Context, Stacktrace) and log the structured error object.
- References for advanced patterns: Assertions configuration and recommended practices are documented in references/advanced.md.
Quick Start
Use the golang-samber-oops skill to rewrite error handling so each error is built with a fluent builder, includes .In domain + .Code error slug + structured attributes via .With/.User/.Tenant, uses .Public for user-safe messaging, and converts goroutine panics with .Recover.