better-result-adopt

Migrate try/catch and promise error handling to typed Result patterns at I/O boundaries.

5|Updated Feb 6, 2022
One-click install
npx skills add https://github.com/christofferbergj/dotfiles --skill better-result-adopt-christofferbergj
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: better-result-adopt
Source: https://github.com/christofferbergj/dotfiles/tree/main/.agents/skills/better-result-adopt
Command: npx skills add https://github.com/christofferbergj/dotfiles --skill better-result-adopt-christofferbergj

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Migrate codebases from try/catch or Promise-based error handling to typed Result-based error handling with better-result, reducing untyped errors and improving type safety.

Core Features & Use Cases

  • Identify error boundaries and domain errors
  • Define TaggedError types and Result wrappers
  • Refactor I/O paths and propagate Result through call stacks
  • Provide a structured migration plan at boundaries

Quick Start

Begin by identifying an I/O boundary and wrapping its calls with Result.try/tryPromise to start migrating to typed results.

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 patterns?

To migrate TypeScript error handling to typed Result patterns, wrap I/O boundaries like API calls and database queries with Result.try and tryPromise, define domain errors using TaggedError, and update function signatures to return Result types.

What is the best way to replace try/catch blocks with typed errors in a TypeScript codebase?

Replacing try/catch blocks with typed errors involves identifying I/O boundaries, wrapping promise rejections with Result.tryPromise, and propagating Result types through the call stack to eliminate untyped errors.

How does TaggedError work when defining domain errors for API calls?

TaggedError defines domain errors by tagging specific failure cases at I/O boundaries, allowing API calls and file operations to return structured Result types instead of throwing untyped exceptions.

Can I use better-result to refactor existing Promise-based error handling without external dependencies?

Yes, better-result operates without external dependencies to refactor Promise-based error handling, allowing you to wrap promise rejections at I/O boundaries and convert them to typed Result wrappers.

When do I need typed Result wrappers for database queries and file operations?

Typed Result wrappers are needed for database queries and file operations when you want to enforce type safety at I/O boundaries, replacing unpredictable try/catch blocks with explicit domain error propagation.

What are the limitations of refactoring to typed Result patterns across an existing codebase?

Refactoring to typed Result patterns requires updating function signatures across the call stack, meaning all downstream callers must be migrated to handle Result types, which can impact large codebases significantly.