better-result-adopt

Migrate try/catch error handling to typed Result-based flows with better-result.

Updated Apr 4, 2023
One-click install
npx skills add https://github.com/Andrewy-gh/cut-above --skill better-result-adopt-andrewy-gh
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: better-result-adopt
Source: https://github.com/Andrewy-gh/cut-above/tree/main/server/.codex/skills/better-result-adopt
Command: npx skills add https://github.com/Andrewy-gh/cut-above --skill better-result-adopt-andrewy-gh

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Migrate error handling from try/catch, Promise rejections, and thrown exceptions to typed Result-based error handling using better-result.

Core Features & Use Cases

  • Define domain-level errors as TaggedError classes.
  • Wrap boundaries with Result.try/tryPromise to migrate error paths safely.
  • Convert legacy checks to Result chains and railway-oriented programming.
  • Gradually migrate callers and ensure type-safe error propagation across API, IO, and business logic.

Quick Start

Create a minimal TaggedError for a domain error, wrap a sample API call with Result.tryPromise, and propagate the Result through a simple call chain.

Frequently Asked Questions about better-result-adopt

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

FAQPage Schema
How do I migrate error handling from try/catch to typed Result objects in TypeScript?

To migrate error handling to typed Result objects in TypeScript, define domain-level errors as TaggedError classes, wrap boundaries with Result.try/tryPromise, and update callers to return Result types with typed error unions.

What is railway-oriented programming for TypeScript error handling?

Railway-oriented programming for TypeScript error handling structures synchronous and asynchronous code paths into Result chains, replacing thrown exceptions and Promise rejections with typed, propagating Result objects.

How can I convert Promise rejections to typed errors without breaking existing API callers?

You can convert Promise rejections to typed errors by gradually wrapping API and IO boundaries with Result.tryPromise, then migrating callers to handle the returned Result types and typed error unions safely.

Does this approach support gradual migration of legacy TypeScript error paths?

Yes, this approach supports gradually migrating legacy TypeScript error paths by wrapping specific boundaries with Result.try or tryPromise first, then progressively updating callers to ensure type-safe error propagation.

What is the best way to define domain-level errors for TypeScript refactoring?

The best way to define domain-level errors for TypeScript refactoring is creating minimal TaggedError classes, which allow you to categorize and type-safely propagate business logic errors as typed Result objects.