go-error-handling

Go Error Handling Skill

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 linehaul-ai/linehaulai-claude-marketplace/linehaul-ai-linehaulai-claude-marketplace-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

Document Description When to Use

error-wrapping.md How to wrap errors with %w for chain inspection Use when returning errors from functions to preserve the error chain. Essential if callers need to use errors.Is() or errors.As() .

error-types.md When to use sentinel vs typed errors Use 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.md Defining and using domain-specific errors Use 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.md gRPC error handling and status codes Use 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.

General

geospatial-postgis-patterns

No summary provided by upstream source.

Repository SourceNeeds Review
General

rbac-authorization-patterns

No summary provided by upstream source.

Repository SourceNeeds Review
General

quickbooks-online-api

No summary provided by upstream source.

Repository SourceNeeds Review
General

slack-block-kit

No summary provided by upstream source.

Repository SourceNeeds Review