errors-go

Define and register typed error codes with HTTP status mapping for Go bounded contexts.

4|Updated Jul 30, 2026
One-click install
npx skills add https://github.com/gabriellst/codm --skill errors-go-gabriellst
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: errors-go
Source: https://github.com/gabriellst/codm/tree/main/.claude/skills/errors/go
Command: npx skills add https://github.com/gabriellst/codm --skill errors-go-gabriellst

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Go services need consistent HTTP error responses, but ad-hoc error handling with fmt.Errorf bypasses status mapping and silently returns 500 for every failure. This Skill standardizes how domain and application error codes are declared, registered, and raised in a Go bounded context. ## Core Features & Use Cases - Typed Error Code Declaration: Declare constants as errors.ErrorCode in internal/<ctx>/errors/codes.go and register each one with an HTTP status via init() and errors.RegisterErrorCodes. - Startup Registration Wiring: Trigger init() through a mandatory anonymous import in module.go so the MapErrorToHTTP middleware resolves codes correctly. - Correct Error Raising: Raise failures with errors.NewBaseError instead of fmt.Errorf so the HTTP mapper can extract the code, and reuse core framework codes without re-declaring them. - Use Case: When adding a new transcoding context, define codes like CodeJobNotFound and CodeJobNotPending, map them to 404 and 409, and have every handler return the right status automatically. ## Quick Start Ask the AI to create the error codes file for a new Go bounded context, register each code with its HTTP status in init(), and add the blank import to module.go.

Frequently Asked Questions about errors-go

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

FAQPage Schema
How do I define custom error codes in a Go service?

Create internal/<ctx>/errors/codes.go and declare constants typed as errors.ErrorCode, then register each one in an init() function via errors.RegisterErrorCodes with the desired HTTP status. Every declared code must appear in the registration map.

How do I map Go errors to HTTP status codes?

Register each error code with an HTTP status in init() using errors.RegisterErrorCodes, and raise failures with errors.NewBaseError. The MapErrorToHTTP middleware then resolves the code to the registered status at runtime.

Why do my Go errors return 500 instead of 404 or 409?

A 500 usually means the code was never registered or the errors package was never imported. Add the blank import _ "template/api-go/internal/<ctx>/errors" to module.go so init() runs, and verify every const appears in RegisterErrorCodes.

Should I use fmt.Errorf or a custom error type for business errors?

Use errors.NewBaseError with a typed code for domain and application errors, because fmt.Errorf produces errors the HTTP mapper cannot unwrap, resulting in status 500. Reserve fmt.Errorf for infrastructure wrapping with %w.

When should I not define new error codes in a Go context?

Do not define codes for validation failures already handled by validate struct tags, infrastructure panics, or codes that already exist in the core errors package such as CodeNotFound or CodeDatabaseError. Reuse core codes directly instead of re-declaring them.