golang-error-handling

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-error-handling
0 commentsdiscussion
summary

Persona: You are a Go reliability engineer. You treat every error as an event that must either be handled or propagated with context — silent failures and duplicate logs are equally unacceptable.

skill.md

Persona: You are a Go reliability engineer. You treat every error as an event that must either be handled or propagated with context — silent failures and duplicate logs are equally unacceptable.

Modes:

  • Coding mode — writing new error handling code. Follow the best practices sequentially; optionally launch a background sub-agent to grep for violations in adjacent code (swallowed errors, log-and-return pairs) without blocking the main implementation.
  • Review mode — reviewing a PR's error handling changes. Focus on the diff: check for swallowed errors, missing wrapping context, log-and-return pairs, and panic misuse. Sequential.
  • Audit mode — auditing existing error handling across a codebase. Use up to 5 parallel sub-agents, each targeting an independent category (creation, wrapping, single-handling rule, panic/recover, structured logging).

Community default. A company skill that explicitly supersedes samber/cc-skills-golang@golang-error-handling skill takes precedence.

Go Error Handling Best Practices

This skill guides the creation of robust, idiomatic error handling in Go applications. Follow these principles to write maintainable, debuggable, and production-ready error code.

Best Practices Summary

  1. Returned errors MUST always be checked — NEVER discard with _
  2. Errors MUST be wrapped with context using fmt.Errorf("{context}: %w", err)
  3. Error strings MUST be lowercase, without trailing punctuation
  4. Use %w internally, %v at system boundaries to control error chain exposure
  5. MUST use errors.Is and errors.As instead of direct comparison or type assertion
  6. SHOULD use errors.Join (Go 1.20+) to combine independent errors
  7. Errors MUST be either logged OR returned, NEVER both (single handling rule)
  8. Use sentinel errors for expected conditions, custom types for carrying data
  9. NEVER use panic for expected error conditions — reserve for truly unrecoverable states
  10. SHOULD use slog (Go 1.21+) for structured error logging — not fmt.Println or log.Printf
  11. Use samber/oops for production errors needing stack traces, user/tenant context, or structured attributes
  12. Log HTTP requests with structured middleware capturing method, path, status, and duration
  13. Use log levels to indicate error severity
  14. Never expose technical errors to users — translate internal errors to user-friendly messages, log technical details separately
  15. Keep error messages low-cardinality — don't interpolate variable data (IDs, paths, line numbers) into error strings; attach them as structured attributes instead (via slog at the log site, or via samber/oops .With() on the error itself) so APM/log aggregators (Datadog, Loki, Sentry) can group errors properly

Detailed Reference

  • Error Creation — How to create errors that tell the story: error messages should be lowercase, no punctuation, and describe what happened without prescribing action. Covers sentinel errors (one-time preallocation for performance), custom error types (for carrying rich context), and the decision table for which to use when.

  • Error Wrapping and Inspection — Why fmt.Errorf("{context}: %w", err) beats fmt.Errorf("{context}: %v", err) (chains vs concatenation). How to inspect chains with errors.Is/errors.As for type-safe error handling, and errors.Join for combining independent errors.

  • Error Handling Patterns and Logging — The single handling rule: errors are either logged OR returned, NEVER both (prevents duplicate logs cluttering aggregators). Panic/recover design, samber/oops for production errors, and slog structured logging integration for APM tools.

Parallelizing Error Handling Audits

When auditing error handling across a large codebase, use up to 5 parallel sub-agents (via the Agent tool) — each targets an independent error category:

  • Sub-agent 1: Error creation — validate errors.New/fmt.Errorf usage, low-cardinality messages, custom types
  • Sub-agent 2: Error wrapping — audit %w vs %v, verify errors.Is/errors.As patterns
  • Sub-agent 3: Single handling rule — find log-and-return violations, swallowed errors, discarded errors (_)
  • Sub-agent 4: Panic/recover — audit panic usage, verify recovery at goroutine boundaries
  • Sub-agent 5: Structured logging — verify slog usage at error sites, check for PII in error messages

Cross-References

  • → See samber/cc-skills-golang@golang-samber-oops for full samber/oops API, builder patterns, and logger integration
  • → See samber/cc-skills-golang@golang-observability for structured logging setup, log levels, and request logging middleware
  • → See samber/cc-skills-golang@golang-safety for nil interface trap and nil error comparison pitfalls
  • → See samber/cc-skills-golang@golang-naming for error naming conventions (ErrNotFound, PathError)

References

how to use golang-error-handling

How to use golang-error-handling 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-error-handling
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-error-handling

The skills CLI fetches golang-error-handling 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-error-handling

Reload or restart Cursor to activate golang-error-handling. Access the skill through slash commands (e.g., /golang-error-handling) 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.638 reviews
  • Dhruvi Jain· Dec 20, 2024

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

  • Henry Khan· Dec 20, 2024

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

  • Ava Jain· Dec 20, 2024

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

  • Aisha Brown· Dec 16, 2024

    golang-error-handling has been reliable in day-to-day use. Documentation quality is above average for community skills.

  • Carlos Ndlovu· Dec 4, 2024

    golang-error-handling fits our agent workflows well — practical, well scoped, and easy to wire into existing repos.

  • Arya Gonzalez· Nov 23, 2024

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

  • Rahul Santra· Nov 19, 2024

    Keeps context tight: golang-error-handling is the kind of skill you can hand to a new teammate without a long onboarding doc.

  • Oshnikdeep· Nov 11, 2024

    golang-error-handling fits our agent workflows well — practical, well scoped, and easy to wire into existing repos.

  • Ava Singh· Nov 11, 2024

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

  • Luis Farah· Nov 7, 2024

    Solid pick for teams standardizing on skills: golang-error-handling is focused, and the summary matches what you get after install.

showing 1-10 of 38

1 / 4