better-result-adopt

Migrate TypeScript try/catch error handling to typed Result-based errors.

814|93|Updated Jun 10, 2016
One-click install
npx skills add https://github.com/nikivdev/ts --skill better-result-adopt-nikivdev
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: better-result-adopt
Source: https://github.com/nikivdev/ts/tree/main/.codex/skills/better-result-adopt
Command: npx skills add https://github.com/nikivdev/ts --skill better-result-adopt-nikivdev

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill helps teams migrate existing error handling from try/catch blocks, Promise rejections, and thrown exceptions to a typed, Result-based approach using better-result, improving reliability and maintainability.

Core Features & Use Cases

  • Define domain errors using TaggedError classes and map them to Result.err
  • Wrap I/O boundaries with Result.try/tryPromise to standardize error flow
  • Refactor callers to propagate Result values and leverage pattern matching

Quick Start

Use this Skill to transform a module that uses try/catch into Result-based error handling by introducing TaggedError classes, and wrapping boundary functions with Result.try or Result.tryPromise.

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 TypeScript error handling from try/catch to Result types?

To migrate TypeScript error handling to Result types, you replace try/catch blocks and Promise rejections with TaggedError classes and wrap I/O boundaries using Result.try or Result.tryPromise. This enables safer, predictable railway-oriented programming.

What is railway-oriented programming in TypeScript?

Railway-oriented programming in TypeScript is an error-handling approach where functions return Result values instead of throwing exceptions. It standardizes error flow by propagating Result types and leveraging pattern matching for predictable code execution.

How do I define domain errors using TaggedError classes?

To define domain errors using TaggedError classes, you create specific error classes extending TaggedError and map them to Result.err. This allows callers to pattern match on specific domain failures instead of catching generic exceptions.

Can I wrap Promise rejections with Result-based error handling?

Yes, you can wrap Promise rejections with Result-based error handling by using Result.tryPromise. This standardizes asynchronous error flows by catching Promise rejections at I/O boundaries and converting them into typed Result values.

Does migrating to better-result work with existing thrown exceptions?

Yes, migrating to better-result works with existing thrown exceptions. It targets codebases using thrown errors or try/catch blocks, applying TaggedError classes and Result boundaries to refactor callers into safer, typed error propagation.

What is the best way to standardize error flow at I/O boundaries in TypeScript?

The best way to standardize error flow at I/O boundaries in TypeScript is wrapping boundary functions with Result.try or Result.tryPromise. This converts unpredictable thrown exceptions and Promise rejections into typed Result values for reliable propagation.