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. |
More from linehaul-ai/linehaulai-claude-marketplace
geospatial-postgis-patterns
Implement geofences, spatial queries, real-time tracking, and mapping features in laneweaverTMS using PostGIS and PGRouting. Use when building location-based features, distance calculations, ETA predictions, or fleet visualization.
83quickbooks-online-api
Expert guide for QuickBooks Online API integration covering authentication, CRUD operations, batch processing, and best practices for invoicing, payments, and customer management.
61rbac-authorization-patterns
Provide patterns for implementing Role-Based Access Control and multi-tenant authorization in laneweaverTMS. Use when implementing user roles, permissions, tenant isolation, Echo authorization middleware, RLS policies for multi-tenant access, or JWT claims structure for freight brokerage applications.
61slack-block-kit
Build Slack Block Kit UIs for messages, modals, and Home tabs. Use when creating Slack notifications, interactive forms, bot responses, app dashboards, or any Slack UI. Covers blocks (Section, Actions, Input, Header), elements (Buttons, Selects, Date pickers), composition objects, and the slack-block-builder library.
44svelte-flow
Build node-based editors, interactive diagrams, and flow visualizations using Svelte Flow. Use when creating workflow editors, data flow diagrams, organizational charts, mindmaps, process visualizations, DAG editors, or any interactive node-graph UI. Supports custom nodes/edges, layouts (dagre, hierarchical), animations, and advanced features like proximity connect, floating edges, and contextual zoom.
35testcontainers-go
Use this skill when writing Go integration tests with Docker containers, using testcontainers-go modules (postgres, redis, kafka, etc.), setting up container-based test infrastructure, or configuring container networking and wait strategies. Covers 62+ pre-configured modules, cleanup patterns, and multi-container setups.
34