golang-samber-oops

samber/cc-skills-golang · updated Apr 8, 2026

MDX-style export adds YAML metadata + attribution linking explainx.ai and this canonical listing URL.

$npx skills add https://github.com/samber/cc-skills-golang --skill golang-samber-oops
0 commentsdiscussion
summary

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.

skill.md

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. Context7 can help as a discoverability platform.

Core pattern: Error builder chain

All oops errors use a fluent builder pattern:

err := oops.
    In("user-service").           // domain/feature
    Tags("database", "postgres").  // categorization
    Code("network_failure").       // machine-readable identifier
    User("user-123", "email", "[email protected]").  // user context
    With("query", query).          // custom attributes
    Errorf("failed to fetch user: %s", "timeout")

Terminal methods:

  • .Errorf(format, args...) — create a new error
  • .Wrap(err) — wrap an existing error
  • .Wrapf(err, format, args...) — wrap with a message
  • .Join(err1, err2, ...) — combine multiple errors
  • .Recover(fn) / .Recoverf(fn, format, args...) — convert panic to error

Error builder methods

Methods Use case
.With("key", value) Add custom key-value attribute (lazy func() any values supported)
.WithContext(ctx, "key1", "key2") Extract values from Go context into attributes (lazy values supported)
.In("domain") Set the feature/service/domain
.Tags("auth", "sql") Add categorization tags (query with err.HasTag("tag"))
.Code("iam_authz_missing_permission") Set machine-readable error identifier/slug
.Public("Could not fetch user.") Set user-safe message (separate from technical details)
.Hint("Runbook: https://doc.acme.org/doc/abcd.md") Add debugging hint for developers
.Owner("team/slack") Identify responsible team/owner
.User(id, "k", "v") Add user identifier and attributes
.Tenant(id, "k", "v") Add tenant/organization context and attributes
.Trace(id) Add trace / correlation ID (default: ULID)
.Span(id) Add span ID representing a unit of work/operation (default: ULID)
.Time(t) Override error timestamp (default: time.Now())
.Since(t) Set duration based on time since t (exposed via err.Duration())
.Duration(d) Set explicit error duration
.Request(req, includeBody) Attach *http.Request (optionally including body)
.Response(res, includeBody) Attach *http.Response (optionally including body)
oops.FromContext(ctx) Start from an OopsErrorBuilder stored in a Go context

Common scenarios

Database/repository layer

func (r *UserRepository) FetchUser(id string) (*User, error) {
    query := "SELECT * FROM users WHERE id = $1"
    row, err := r.db.Query(query, id)
    if err != nil {
        return nil, oops.
            In("user-repository").
            Tags("database", "postgres").
            With("query", query).
            With("user_id", id).
            Wrapf(err, "failed to fetch user from database")
    }
    // ...
}

HTTP handler layer

func (h *Handler) CreateUser(w http.ResponseWriter, r *http.Request) {
    userID := getUserID(r)

    err := h.service.CreateUser(r.Context(), userID)
    if err != nil {
        return oops.
            In("http-handler").
            Tags("endpoint", "/users").
            Request(r, false).
            User(userID).
            Wrapf(err, "create user failed")
    }

    w.WriteHeader(http.StatusCreated)
}

Service layer with reusable builder

func (s *UserService) CreateOrder(ctx context.Context, req CreateOrderRequest) error {
    builder := oops.
        In("order-service").
        Tags("orders", "checkout").
        Tenant(req.TenantID, "plan", req.Plan).
        User(req.UserID, "email", req.UserEmail)

    product, err := s.catalog.GetProduct(ctx, req.ProductID)
    if err != nil {
        return builder.
            With("product_id", req.ProductID).
            Wrapf(err, "product lookup failed")
    }

    if product.Stock < req.Quantity {
        return builder.
            Code("insufficient_stock").
            Public("Not enough items in stock.").
            With("requested", req.Quantity).
            With("available", product.Stock).
            Errorf("insufficient stock for product %s", req.ProductID)
    }

    return nil
}

Error wrapping best practices

DO: Wrap directly, no nil check needed

// ✓ Good — Wrap returns nil if err is nil
return oops.Wrapf(err, "operation failed")

// ✗ Bad — unnecessary nil check
if err != nil {
    return oops.Wrapf(err, "operation failed")
}
return nil

DO: Add context at each layer

Each architectural layer SHOULD add context via Wrap/Wrapf — at least once per package boundary (not necessarily at every function call).

// ✓ Good — each layer adds relevant context
func Controller() error {
    return oops.In("controller").Trace(traceID).Wrapf(Service(), "user request failed")
}

func Service() error {
    return oops.In("service").With("op", "create_user").Wrapf(Repository(), "db operation failed")
}

func Repository
how to use golang-samber-oops

How to use golang-samber-oops on Cursor

AI-first code editor with Composer

1

Prerequisites

Before installing skills in Cursor, ensure your development environment meets these requirements:

  • Cursor installed and configured on your development machine
  • Node.js version 16.0+ with npm package manager (verify with node --version)
  • Active project directory or workspace where you want to add golang-samber-oops
2

Execute installation command

Execute the skills CLI command in your project's root directory to begin installation:

$npx skills add https://github.com/samber/cc-skills-golang --skill golang-samber-oops

The skills CLI fetches golang-samber-oops from GitHub repository samber/cc-skills-golang and configures it for Cursor.

3

Select Cursor when prompted

The CLI will show a list of available agents. Use arrow keys to navigate and space to select Cursor:

◆ Which agents do you want to install to?
│ ── Universal (.agents/skills) ── always included ────
│ • Amp
│ • Antigravity
│ • Cline
│ • Codex
│ ●Cursor(selected)
│ • Cursor
│ • Windsurf
4

Verify installation

Confirm successful installation by checking the skill directory location:

.cursor/skills/golang-samber-oops

Reload or restart Cursor to activate golang-samber-oops. Access the skill through slash commands (e.g., /golang-samber-oops) or your agent's skill management interface.

Security & Verification Notice

We perform automated surface-level scans (Gen AI Scanner, Socket, Snyk) during installation. These checks detect common vulnerabilities but do not guarantee complete security. Always review skill source code and verify the publisher's reputation before production use.

Skills execute code in your development environment. Always verify the publisher's identity, review recent commits, and test in isolated environments before production deployment.

List & Monetize Your Skill

Submit your Claude Code skill and start earning

GET_STARTED →

Use Cases

Task Automation & Efficiency

Automate repetitive workflows and reduce manual effort

Example

Generate reports, summarize documents, draft communications

Save 3-5 hours per week on routine tasks

Knowledge Enhancement

Learn new skills, understand complex topics, get expert guidance

Example

Explain concepts, provide examples, suggest learning resources

Accelerate learning and skill development by 2x

Quality Improvement

Enhance output quality through reviews, suggestions, and refinements

Example

Review drafts, suggest improvements, catch errors

Improve work quality by 30-40% with less effort

Implementation Guide

Prerequisites

  • Claude Desktop or compatible AI client with skill support
  • Clear understanding of task or problem to solve
  • Willingness to iterate and refine outputs

Time Estimate

15-45 minutes depending on use case complexity

Installation Steps

  1. 1.Install skill using provided installation command
  2. 2.Test with simple use case relevant to your work
  3. 3.Evaluate output quality and relevance
  4. 4.Iterate on prompts to improve results
  5. 5.Integrate into regular workflow if valuable

Common Pitfalls

  • Expecting perfect results without iteration
  • Not providing enough context in prompts
  • Using skill for tasks outside its intended scope
  • Accepting outputs without review and validation

Best Practices

✓ Do

  • +Start with clear, specific prompts
  • +Provide relevant context and constraints
  • +Review and refine all outputs before using
  • +Iterate to improve output quality
  • +Document successful prompt patterns

✗ Don't

  • Don't use without understanding skill limitations
  • Don't skip validation of outputs
  • Don't share sensitive information in prompts
  • Don't expect skill to replace human judgment

💡 Pro Tips

  • Be specific about desired format and style
  • Ask for multiple options to choose from
  • Request explanations to understand reasoning
  • Combine AI efficiency with human expertise

When to Use This

✓ Use When

Use when skill capabilities match your task, clear ROI on time saved, and you can validate outputs. Best for repetitive tasks, learning, and quality improvement.

✗ Avoid When

Avoid when task requires deep expertise you can't validate, involves sensitive decisions, or when learning process is more valuable than speed of completion.

Learning Path

  1. 1Familiarize yourself with skill capabilities and limitations
  2. 2Start with low-risk, non-critical tasks
  3. 3Progress to more complex and valuable use cases
  4. 4Build expertise through regular use and experimentation

Discussion

Product Hunt–style comments (not star reviews)
  • No comments yet — start the thread.
general reviews

Ratings

4.548 reviews
  • Nikhil Anderson· Dec 28, 2024

    I recommend golang-samber-oops for anyone iterating fast on agent tooling; clear intent and a small, reviewable surface area.

  • Anika Torres· Dec 20, 2024

    Registry listing for golang-samber-oops matched our evaluation — installs cleanly and behaves as described in the markdown.

  • Tariq Okafor· Dec 4, 2024

    Useful defaults in golang-samber-oops — fewer surprises than typical one-off scripts, and it plays nicely with `npx skills` flows.

  • Zaid Agarwal· Nov 23, 2024

    Registry listing for golang-samber-oops matched our evaluation — installs cleanly and behaves as described in the markdown.

  • Anika Ramirez· Nov 19, 2024

    golang-samber-oops reduced setup friction for our internal harness; good balance of opinion and flexibility.

  • Arjun Smith· Nov 11, 2024

    Useful defaults in golang-samber-oops — fewer surprises than typical one-off scripts, and it plays nicely with `npx skills` flows.

  • Aisha Khanna· Oct 14, 2024

    golang-samber-oops reduced setup friction for our internal harness; good balance of opinion and flexibility.

  • Arjun Johnson· Oct 10, 2024

    Registry listing for golang-samber-oops matched our evaluation — installs cleanly and behaves as described in the markdown.

  • Nikhil Li· Oct 2, 2024

    I recommend golang-samber-oops for anyone iterating fast on agent tooling; clear intent and a small, reviewable surface area.

  • Sakshi Patil· Sep 21, 2024

    golang-samber-oops is among the better-maintained entries we tried; worth keeping pinned for repeat workflows.

showing 1-10 of 48

1 / 5