go-error-handling-patterns

Standardize Go error handling with a unified AppError hierarchy and HTTP status mapping.

Updated Aug 23, 2026
One-click install
npx skills add https://github.com/PremModhaOfficial/go-sdk-pipeline --skill go-error-handling-patterns
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: go-error-handling-patterns
Source: https://github.com/PremModhaOfficial/go-sdk-pipeline/tree/main/.claude/skills/go-error-handling-patterns
Command: npx skills add https://github.com/PremModhaOfficial/go-sdk-pipeline --skill go-error-handling-patterns

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Go applications often duplicate error handling logic, leading to inconsistent messages and debugging challenges. This skill provides a unified AppError type and a standardized error workflow across services, including stack traces for debugging while emitting user-safe messages to clients.

Core Features & Use Cases

  • Unified AppError type with Code, Message, Detail, HTTPStatus, and stack traces, enabling consistent error responses and easier tracing.
  • Constructors for common domain errors (NotFound, Validation, Unauthorized, Forbidden, Internal, TenantMismatch), plus a simple Internal wrapper for unexpected causes.
  • Error wrapping with fmt.Errorf %w to preserve error chains for errors.Is / errors.As.
  • Domain-level error catalogs and sentinel errors to centralize domain semantics and reduce duplication.
  • PII-safe user messages with internal details kept in non-serialized fields for debugging.

Quick Start

Start using the shared AppError constructors in your services to emit consistent, safe errors.

Frequently Asked Questions about go-error-handling-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I standardize Go error handling across multiple services?▼

Standardize Go error handling by implementing a unified AppError type with consistent Code, Message, Detail, and HTTPStatus fields. This approach eliminates duplicated logic across services, ensuring consistent error responses and stack traces for debugging.

How do I map domain errors to HTTP status codes in Go?▼

Map domain errors to HTTP status codes using predefined constructors like NotFound, Validation, Unauthorized, and Forbidden. These constructors automatically assign the correct HTTPStatus to your AppError, streamlining HTTP handler responses.

What is the best way to wrap Go errors while preserving the error chain?▼

Wrap Go errors using fmt.Errorf with the %w verb to preserve the error chain. This allows errors.Is and errors.As to traverse the wrapped errors, maintaining domain semantics through sentinel errors and an error catalog.

How do I prevent PII from leaking in Go API error messages?▼

Prevent PII leaks by keeping internal details in non-serialized fields within the AppError type. This ensures only user-safe messages are emitted to clients, while sensitive information remains accessible internally for debugging.

When should I use sentinel errors vs an error catalog in Go?▼

Use sentinel errors for specific expected values and an error catalog to centralize domain semantics across services. Both reduce duplication, but the catalog groups broader domain categories while sentinels handle exact error matching via errors.Is.