Xpersona
G

golang-samber-oops

CLAWHUB · Unverified

Structured error handling in Golang with samber/oops — error builders, stack traces, error codes, error context, error wrapping, error attributes, user-facing vs developer messages, panic recovery, and logger integration. Apply when using or adopting samber/oops, or when the codebase already imports github.com/samber/oops. Skill: golang-samber-oops Owner: samber Summary: Structured error handling in Golang with samber/oops — error builders, stack traces, error codes, error context, error wrapping, error attributes, user-facing vs developer messages, panic recovery, and logger integration. Apply when using or adopting samber/oops, or when the codebase already imports github.com/samber/oops. Tags: latest:1.2.0 Version history: v1.2.0 | 2

62
Rank
84
Safety
1.2k
Downloads

About

What it does, and when to use it.

Capability contract not published. No trust telemetry is available yet. 1.2K downloads reported by the source. Last updated 10/10/2026.

Avoid when

  • Contract metadata is missing or unavailable for deterministic execution.

Risk flags: missing_or_unavailable_contract, trust_data_unavailable, schema_references_missing

Install and run

Setup complexity: low.

clawhub skill install s173arkhs3131fq5jf769qq75583hdgt:golang-samber-oops
  1. Setup complexity is LOW. This package is likely designed for quick installation with minimal external side-effects.
  2. Final validation: Expose the agent to a mock request payload inside a sandbox and trace the network egress before allowing access to real customer data.

Contract: missing

curl -s "https://www.xpersona.co/api/v1/agents/clawhub-samber-golang-samber-oops/snapshot"

Run-check

$0.02 USD

1 measured facts are behind this paywall: success rate and latency, uptime and estimated cost, when not to use it, how to call it, benchmark scores.

Agents pay $0.02 in USDC. A card payment is $0.50, the smallest a card allows.

Documentation

CLAWHUB

115,510 characters of source documentation, loaded on request.

Extracted files

5 files captured from the source.

SKILL.md

---
name: golang-samber-oops
description: "Structured error handling in Golang with samber/oops — error builders, stack traces, error codes, error context, error wrapping, error attributes, user-facing vs developer messages, panic recovery, and logger integration. Apply when using or adopting samber/oops, or when the codebase already imports github.com/samber/oops."
user-invocable: true
license: MIT
compatibility: Designed for Claude Code, Codex or similar harness, and for projects using Golang.
metadata:
  author: samber
  version: "1.2.0"
  openclaw:
    emoji: "💥"
    homepage: https://github.com/samber/cc-skills-golang
    requires:
      bins:
        - go
    install: []
    skill-library-version: "1.21.0"
allowed-tools: Read Edit Write Glob Grep Bash(go:*) Bash(golangci-lint:*) Bash(git:*) Agent WebFetch mcp__context7__resolve-library-id mcp__context7__query-docs Bash(godig:*) Bash(gopls:*) LSP mcp__gopls__*
paths:
  - "**/*.go"
---

**Persona:** You are a Go engineer who treats errors as structured data. Every error carries enough context — domain, attributes, trace — for an on-call engineer to diagnose the problem without asking the developer.

# samber/oops Structured Error Handling

**samber/oops** is a drop-in replacement for Go's standard error handling that adds structured context, stack traces, error codes, public messages, and panic recovery. Variable data goes in `.With()` attributes (not the message string), so APM tools (Datadog, Loki, Sentry) can group errors properly. Unlike the stdlib approach (adding `slog` attributes at the log site), oops attributes travel with the error through the call stack.

## Why use samber/oops

Standard Go errors lack context — you see `connection failed` but not which user triggered it, what query was running, or the full call stack. `samber/oops` provides:

- **Structured context** — key-value attributes on any error
- **Stack traces** — automatic call stack capture
- **Error codes** — machine-readable identifiers
- **Public messages** — user-safe messages separate from technical details
- **Low-cardinality messages** — variable data in `.With()` attributes, not the message string, so APM tools group errors properly

This skill is not exhaustive. Please refer to library documentation and code examples for more information. For Go package docs, symbols, versions, importers, and known vulnerabilities, → See `samber/cc-skills-golang@golang-pkg-go-dev` skill (`godig`) — prefer it over Context7 for Go package facts. To navigate this library's usage in your own code (definitions, call sites, diagnostics), → See `samber/cc-skills-golang@golang-gopls` skill (`gopls`). Context7 remains a fallback for docs not indexed on pkg.go.dev.

## Core pattern: Error builder chain

All `oops` errors use a fluent builder pattern:

```go
err := oops.
    In("user-service").           // domain/feature
    Tags("database", "postgres").  // categorization
    Code("network_failure").       // machine-readable identifie

_meta.json

{
  "ownerId": "kn72rhnkwjfeex9wr1n7y24qa983cjn3",
  "slug": "golang-samber-oops",
  "version": "1.2.0",
  "publishedAt": 1787434176871
}

references/advanced.md

# samber/oops — Advanced Patterns

## Assertions

Use assertions for invariant checks (carefully — assertions panic):

```go
func ProcessPayment(amount int) error {
    return oops.
        In("payment-service").
        Recover(func() {
            oops.Assertf(amount > 0, "amount must be positive, got %d", amount)
            oops.Assert(amount < 1_000_000)
            // ... payment logic
        })
}
```

Assertions should be rare in Go. Use them only for truly impossible states that indicate a bug.

## Configuration

```go
oops.StackTraceMaxDepth = 20          // adjust stack trace depth
oops.SourceFragmentsHidden = false    // enable source code fragments
loc, _ := time.LoadLocation("America/New_York")
oops.Local = loc                      // set timezone for error timestamps
```

## Logger integration

`samber/oops` works with any logger. The error struct provides methods for extracting structured data:

```go
oopsErr := err.(oops.OopsError)
fmt.Println("operation failed",
    "code", oopsErr.Code(),
    "domain", oopsErr.Domain(),
    "user_id", oopsErr.User(),
    "error", oopsErr,
)

// With slog
slog.Error(err.Error(), slog.Any("error", err))

// With zerolog (formatter available)
log.Error().Err(err).Msg("operation failed")

// With logrus (formatter available)
log.WithError(err).Error("operation failed")
```

skill-card.md

## Description:

Structured error handling in Golang with samber/oops - error builders, stack traces, error codes, error context, error wrapping, error attributes, user-facing vs developer messages, panic recovery, and logger integration.

This skill is ready for commercial/non-commercial use.

## Publisher:

[samber](https://clawhub.ai/user/samber)

### License/Terms of Use:

MIT-0

## Use Case:

Developers and engineers use this skill to guide agents working in Go codebases that use or are adopting samber/oops for structured error handling, panic recovery, error context propagation, and logger integration.

### Deployment Geography for Use:

Global

## Known Risks and Mitigations:

Risk: Generated examples may include personal data or HTTP request details in logs or structured error attributes.

Mitigation: Review examples before production use; avoid raw emails, request or response bodies, authorization headers, cookies, tokens, query strings, and unsanitized full request objects. Prefer allowlists, opaque identifiers, redaction, and privacy-aware retention controls.

## Reference(s):

- [ClawHub skill page](https://clawhub.ai/samber/skills/golang-samber-oops)
- [Skill homepage](https://github.com/samber/cc-skills-golang)
- [github.com/samber/oops](https://github.com/samber/oops)
- [pkg.go.dev/github.com/samber/oops](https://pkg.go.dev/github.com/samber/oops)
- [samber/oops - Advanced Patterns](references/advanced.md)

## Skill Output:

**Output Type(s):** [Text, Markdown, Code, Shell commands, Configuration, Guidance]

**Output Format:** [Markdown with Go code blocks and command examples]

**Output Parameters:** [1D]

**Other Properties Related to Output:** [May include Go error-handling examples, diagnostic commands, and configuration guidance.]

## Skill Version(s):

1.2.0 (source: server release metadata and skill frontmatter)

## Ethical Considerations:

Users should evaluate whether this skill is appropriate for their environment, review any generated or modified files before relying on them, and apply their organization's safety, security, and compliance requirements before deployment.

evals/evals.json

[
  {
    "id": 1,
    "name": "low-cardinality-error-messages",
    "description": "Tests the critical rule: variable data goes in .With() attributes, not interpolated into the message string",
    "prompt": "I'm using samber/oops in my Go service. Write error handling for a function that processes orders. When an order fails, I need to include the user ID, tenant ID, and order ID in the error for debugging.",
    "trap": "Model may interpolate all variables into the Errorf message string (e.g., Errorf('failed to process order %s for user %s in tenant %s', orderID, userID, tenantID)) which breaks APM grouping",
    "assertions": [
      {"id": "1.1", "text": "Uses .With() for user_id, tenant_id, and order_id instead of interpolating them into the message"},
      {"id": "1.2", "text": "The Errorf/Wrapf message string is static/low-cardinality (no variable interpolation for IDs)"},
      {"id": "1.3", "text": "Uses the fluent builder pattern (chained method calls)"},
      {"id": "1.4", "text": "Does NOT use fmt.Errorf or errors.New for the error creation"},
      {"id": "1.5", "text": "Includes .In() to set the domain/feature context"}
    ]
  },
  {
    "id": 2,
    "name": "wrap-nil-passthrough",
    "description": "Tests that oops.Wrap returns nil if err is nil, so no nil check is needed",
    "prompt": "I have a Go function using samber/oops. It calls another function that may return nil or an error. How should I handle the return value? Here's my code:\n\n```go\nfunc ProcessData(ctx context.Context) error {\n    err := fetchData(ctx)\n    if err != nil {\n        return oops.In(\"processor\").Wrapf(err, \"fetch failed\")\n    }\n    return nil\n}\n```\n\nIs there a simpler way to write this?",
    "trap": "Model may say the code is fine as-is, not knowing that oops.Wrap/Wrapf returns nil when err is nil, making the nil check unnecessary",
    "assertions": [
      {"id": "2.1", "text": "Identifies that the nil check is unnecessary because oops.Wrapf returns nil if err is nil"},
      {"id": "2.2", "text": "Shows the simplified form: return oops.In('processor').Wrapf(err, 'fetch failed') without the if block"},
      {"id": "2.3", "text": "The simplified version removes both the if statement and the separate return nil"}
    ]
  },
  {
    "id": 3,
    "name": "layered-error-context",
    "description": "Tests that each architectural layer should add context via Wrap/Wrapf at package boundaries",
    "prompt": "I have a 3-layer Go architecture: HTTP handler -> service -> repository. Each layer calls the next. How should I handle errors with samber/oops so that when an error reaches the top, I can see the full context of what happened at each layer?",
    "trap": "Model may only wrap at the top level or only at the bottom level, instead of wrapping at each layer boundary with layer-specific context",
    "assertions": [
      {"id": "3.1", "text": "Each layer (handler, service, repository) adds its own .In() domain context"},
      {"id": "3.

Sponsored

Ads related to golang-samber-oops and adjacent AI workflows.