go-error-handling

Best practices for error handling in Go applications, including error wrapping, domain errors, sentinel vs typed errors, and gRPC error mapping.

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "go-error-handling" with this command: npx skills add imrenagi/skills/imrenagi-skills-go-error-handling

Go Error Handling Skill

This skill provides guidelines for implementing robust error handling in Go applications. Apply these practices when writing, reviewing, or refactoring Go code that involves error creation, propagation, or handling.

When to Use This Skill

Use this skill when:

  • Creating new functions or methods that return errors
  • Implementing repository or service layers that interact with databases or external services
  • Building gRPC or HTTP handlers that need to translate errors to status codes
  • Reviewing code for proper error handling patterns
  • Debugging error propagation issues

Core Principles

Error Handling Decision Flowchart

Error Occurs
    │
    ▼
Is it from an external dependency (DB, API, etc)?
    │
    ├── YES → Map to domain error + wrap with %w
    │
    └── NO → Is it a business rule violation?
              │
              ├── YES → Return appropriate domain error
              │
              └── NO → Wrap and propagate with context

At Handler Layer:
    │
    ▼
Log full error, return safe message to client

References

DocumentDescriptionWhen to Use
error-wrapping.mdHow to wrap errors with %w for chain inspectionUse when returning errors from functions to preserve the error chain. Essential if callers need to use errors.Is() or errors.As().
error-types.mdWhen to use sentinel vs typed errorsUse when deciding between var ErrXxx = errors.New() and custom error structs. Prefer typed errors when you need to attach metadata like resource IDs or permissions.
error-domain-error.mdDefining and using domain-specific errorsUse when building repository or service layers. Maps technology-specific errors (e.g., sql.ErrNoRows) to domain errors to decouple business logic from infrastructure.
server-grpc-error.mdgRPC error handling and status codesUse when implementing gRPC handlers. Covers mapping domain errors to gRPC status codes and adding rich error details like field violations.

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

Coding

protobuf-developer

No summary provided by upstream source.

Repository SourceNeeds Review
Coding

go-development

No summary provided by upstream source.

Repository SourceNeeds Review
General

Find Skills for ClawHub

Search for and discover OpenClaw skills from ClawHub (the official skill registry). Activate when user asks about finding skills, installing skills, or wants...

Registry SourceRecently Updated
1276
Profile unavailable