brokle-error-handling

Standardize Go error handling across repository, service, and handler layers.

3|2|Updated Sep 4, 2025
One-click install
npx skills add https://github.com/brokle-ai/brokle --skill brokle-error-handling
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: brokle-error-handling
Source: https://github.com/brokle-ai/brokle/tree/main/.claude/skills/brokle-error-handling
Command: npx skills add https://github.com/brokle-ai/brokle --skill brokle-error-handling

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill standardizes error handling across Brokle's Go backend, ensuring consistent error propagation, clear error messages, and proper HTTP response mapping. It reduces debugging time and improves API reliability.

Core Features & Use Cases

  • Three-Layer Pattern: Guides on the "Repository (Domain Errors) → Service (AppErrors) → Handler (HTTP Response)" flow for clean architecture.
  • Domain Alias Pattern: Enforces mandatory professional domain aliases for clean and unambiguous error imports.
  • AppError Constructors: Provides a comprehensive list and usage examples for standardized application-level errors, ensuring consistent error responses.
  • Use Case: A developer is implementing a new service and needs to handle a "resource not found" scenario. This skill shows them how to catch the domain error from the repository, convert it to an appErrors.NewNotFoundError, and ensure the handler automatically returns a 404 Not Found HTTP status.

Quick Start

I am implementing a new project service. Show me how to handle a project not found error from the repository, convert it to an AppError, and ensure the HTTP handler returns the correct status code.

Frequently Asked Questions about brokle-error-handling

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

FAQPage Schema
How do I implement consistent error handling across Go backend services?

Error handling consistency in Go backends follows a three-layer pattern: Repository layers emit domain errors, Service layers convert them to AppErrors, and Handler layers map AppErrors to HTTP responses. This standardizes error propagation, reduces debugging time, and ensures predictable API reliability across your codebase.

What's the correct way to handle 'resource not found' errors in a clean architecture Go service?

Catch the domain error from the Repository layer, convert it using an AppError constructor like `appErrors.NewNotFoundError`, then let the Handler layer automatically map it to a 404 HTTP response. This enforces consistent status codes and error messages across all endpoints.

Why should I use domain aliases for error handling in Go?

Domain aliases provide clean, unambiguous error imports and prevent naming collisions across your codebase. They make error types explicit and maintainable, improving code clarity and reducing confusion when multiple packages define similar error concepts.

How do I standardize HTTP error responses in a three-layer Go backend?

Use centralized `response.Error` mapping at the Handler layer with zero logging, standardized error wrapping via `fmt.Errorf` and `errors.Is`, and AppError constructors from the Service layer. This ensures all endpoints return consistent HTTP statuses and error structures.

Can I use context-wrapped domain errors in Go service layers?

Yes. Context-wrapped domain errors preserve error context through the Repository → Service → Handler flow while maintaining proper error identity for `errors.Is` matching. This enables both rich debugging information and reliable error type checking.

What happens if error handling is inconsistent across my Go backend services?

Inconsistent error handling increases debugging time, causes unpredictable API responses, and breaks client error handling logic. Standardizing the Repository → Service → Handler flow with domain aliases and AppError constructors eliminates these issues and improves API reliability.