better-result-adopt

Migrate try/catch and promise rejections to typed Result-based error handling with better-result.

5.6k|317|Updated Feb 10, 2025
One-click install
npx skills add https://github.com/AmanVarshney01/create-better-t-stack --skill better-result-adopt-amanvarshney01
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: better-result-adopt
Source: https://github.com/AmanVarshney01/create-better-t-stack/tree/main/.opencode/skill/better-result-adopt
Command: npx skills add https://github.com/AmanVarshney01/create-better-t-stack --skill better-result-adopt-amanvarshney01

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Migrate existing error handling from try/catch blocks, promise rejections, or thrown errors to typed Result-based error handling using better-result.

Core Features & Use Cases

  • Guided migration against a real-world codebase, starting at I/O boundaries and progressively converting to Result-based error handling.
  • Define domain and infrastructure errors using TaggedError, wrap boundaries with Result.try/tryPromise, and update function signatures accordingly.
  • Refactor callers to propagate Result types and handle errors with typed patterns, improving maintainability and reliability.

Quick Start

Begin by locating I/O boundaries in your codebase and incrementally replace thrown or rejected errors with TaggedError types and Result.try/tryPromise usage.

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 from try/catch blocks to typed Result-based error handling in TypeScript?

To migrate from try/catch to typed Result-based error handling, start at I/O boundaries and replace thrown errors with TaggedError types. Wrap operations using Result.try and Result.tryPromise, then progressively propagate Result types across module function signatures for type-safe failure handling.

What is TaggedError and how does it improve TypeScript error propagation?

TaggedError is a typed error definition pattern that ensures type-safe error propagation by replacing unknown caught errors with explicitly typed failures. It enables generator-based patterns and Result types to guarantee clear, structured failure handling across domain and infrastructure layers.

Can I gradually adopt railway-oriented error handling without rewriting my entire codebase?

Yes, you can gradually adopt railway-oriented error handling by starting at I/O boundaries and incrementally converting to Result types. This approach allows you to progressively propagate typed errors across modules without requiring a full codebase rewrite, improving maintainability step by step.

What's the best way to handle promise rejections using Result types?

The best way to handle promise rejections with Result types is using Result.tryPromise to wrap async boundaries. This converts rejected promises into typed Result failures, allowing you to define infrastructure errors with TaggedError and propagate them safely through your application.

Do I need to define separate TaggedError classes for domain and infrastructure errors?

Yes, defining separate TaggedError classes for domain, infrastructure, and runtime errors is recommended. This categorization ensures clear failure handling boundaries, allowing Result types to accurately represent distinct error sources during type-safe propagation across different application layers.