better-result-adopt

Migrate try/catch and Promise rejections to typed Result flows with better-result.

2|Updated Mar 28, 2024
One-click install
npx skills add https://github.com/cometkim/dotunnel --skill better-result-adopt
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: better-result-adopt
Source: https://github.com/cometkim/dotunnel/tree/main/.opencode/skills/better-result-adopt
Command: npx skills add https://github.com/cometkim/dotunnel --skill better-result-adopt

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Migrate legacy error handling to typed Result-based errors.

Core Features & Use Cases

  • Migration strategy for railway-oriented programming
  • Define and use TaggedError classes to model domain errors
  • Wrap I/O boundaries with Result.try/tryPromise and convert error checks

Quick Start

Start by identifying I/O boundaries in your codebase and marking domain errors with TaggedError classes. Replace try/catch and Promise rejections with Result.try/tryPromise and wrap boundary calls. Update call sites to propagate Result values and use pattern matching to handle success and error cases.

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 to typed Result-based errors?

TypeScript error handling migrates to typed Result-based errors by replacing try/catch blocks and Promise rejections with Result flows. Wrap I/O boundaries using Result.try and Result.tryPromise to ensure safe error propagation and composable railway-oriented programming.

What is railway-oriented programming in TypeScript and how does it handle errors?

Railway-oriented programming in TypeScript models errors as typed values using Result flows instead of exceptions. It enforces defining TaggedError classes to represent domain errors and uses pattern matching to handle success and failure cases compositionally.

How do I convert thrown exceptions into Result flows in JavaScript?

Converting thrown exceptions into Result flows in JavaScript requires wrapping boundary calls with Result.try and Result.tryPromise. This captures exceptions and Promise rejections, returning typed Result values for safe propagation without try/catch blocks.

Do I need to define custom error classes to use typed errors in TypeScript?

Yes, defining custom error classes is required to use typed errors in TypeScript. The migration enforces defining TaggedError classes to accurately model domain errors, enabling type-safe pattern matching and composable error handling across Result flows.

What is the best way to handle I/O boundary errors in TypeScript without try/catch?

The best way to handle I/O boundary errors in TypeScript without try/catch is wrapping them with Result.try and Result.tryPromise. This converts unpredictable I/O failures into typed Result values for safe propagation and pattern matching.

When should I not use typed Result-based errors over try/catch in TypeScript?

You should avoid typed Result-based errors when migrating simple synchronous logic lacking I/O boundaries or domain errors. It targets complex codebases needing railway-oriented programming, requiring TaggedError definitions and pattern matching overhead unsuitable for trivial scripts.