result-pattern

Implement Result<T> returns with ok/fail constructors and HTTP status mappings.

Updated Apr 14, 2026
One-click install
npx skills add https://github.com/BrunoAMSilva/my-config --skill result-pattern-brunoamsilva
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: result-pattern
Source: https://github.com/BrunoAMSilva/my-config/tree/main/coding/skills/result-pattern
Command: npx skills add https://github.com/BrunoAMSilva/my-config --skill result-pattern-brunoamsilva

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Many business operations fail for expected reasons such as validation errors, missing resources, or authorization checks and these failures are often represented as thrown exceptions that are hard to handle predictably across layers. The Result pattern makes those outcomes explicit by returning a value that encodes success or failure so callers must handle each path.

Core Features & Use Cases

  • Explicit error returns: Service methods return a Result type instead of throwing for expected business errors, making error paths visible in the type system.
  • Composable pipelines: map and flatMap allow chaining multiple fallible operations while propagating the first failure.
  • Layer integration: Controllers map Result failures to appropriate HTTP status codes and frontend hooks consume typed error codes to drive UI states.
  • Use Case: Validate request payloads in the service, return Result.fail for validation issues, and let the controller convert those failures into 400/404/409 responses.

Quick Start

Use the result-pattern skill to implement a Result<T> return type in a service, chain validations with flatMap, and map failures to HTTP responses in your controller.

Frequently Asked Questions about result-pattern

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

FAQPage Schema
What is the Result pattern for handling business errors?

The Result pattern makes expected business errors explicit by returning a typed value that encodes success or failure, forcing callers to handle both paths instead of relying on thrown exceptions across application layers.

How do I chain multiple validation operations in a service?

You can chain fallible operations using flatMap and map composition, allowing multiple validations to execute sequentially while automatically propagating the first failure state without throwing exceptions.

How do I map business errors to HTTP status codes in a controller?

Controllers map Result failures to appropriate HTTP status codes, converting validation issues, missing resources, or authorization failures into 400, 404, or 409 responses.

Can I use the Result pattern for frontend error handling?

Yes, frontend hooks can consume typed Result return values to drive UI states, explicitly handling validation failures, not-found errors, and authorization issues with type-safe error codes.

When should I use the Result pattern instead of throwing exceptions?

Use the Result pattern for expected business failures like validation errors, missing resources, or authorization checks, making error paths visible in the type system rather than relying on unpredictable thrown exceptions.

Does the Result pattern work without external dependencies?

Yes, the Result pattern provides a standalone Result<T> type with ok/fail constructors, map and flatMap composition, and controller mappings, requiring no external dependencies to implement type-safe error handling.