KS
Killer-Skills

better-result-adopt — how to use better-result-adopt how to use better-result-adopt, better-result-adopt alternative, better-result-adopt vs TypeScript, better-result-adopt install, better-result-adopt setup guide, typed Result-based error handling, generator-based composition, railway-oriented programming

v1.0.0
GitHub

About this Skill

Perfect for TypeScript Agents needing advanced error handling and typed Result-based composition. better-result-adopt is a TypeScript library that provides a typed Result-based error handling mechanism with generator-based composition.

Features

Migrates existing try/catch blocks to Result types
Replaces thrown exceptions with typed errors
Supports Promise-based code migration to Result.tryPromise
Introduces railway-oriented programming patterns
Enables adoption in existing codebases
Starts migration at boundaries

# Core Topics

dmmulroy dmmulroy
[0]
[0]
Updated: 3/7/2026

Quality Score

Top 5%
48
Excellent
Based on code quality & docs
Installation
SYS Universal Install (Auto-Detect)
Cursor IDE Windsurf IDE VS Code IDE
> npx killer-skills add dmmulroy/better-result/better-result-adopt

Agent Capability Analysis

The better-result-adopt MCP Server by dmmulroy is an open-source Categories.community integration for Claude and other AI agents, enabling seamless task automation and capability expansion. Optimized for how to use better-result-adopt, better-result-adopt alternative, better-result-adopt vs TypeScript.

Ideal Agent Persona

Perfect for TypeScript Agents needing advanced error handling and typed Result-based composition.

Core Value

Empowers agents to migrate existing error handling to typed Result-based error handling with better-result, utilizing generator-based composition and railway-oriented programming patterns, and supporting Result.tryPromise for Promise-based code migration.

Capabilities Granted for better-result-adopt MCP Server

Migrating try/catch blocks to Result types
Replacing thrown exceptions with typed errors
Converting Promise rejections to Result-based error handling
Introducing railway-oriented programming patterns in existing codebases

! Prerequisites & Limits

  • Requires TypeScript environment
  • Limited to error handling and Result-based composition use cases
Project
SKILL.md
5.2 KB
.cursorrules
1.2 KB
package.json
240 B
Ready
UTF-8

# Tags

[No tags]
SKILL.md
Readonly

better-result Adoption

Migrate existing error handling (try/catch, Promise rejections, thrown exceptions) to typed Result-based error handling with better-result.

When to Use

  • Adopting better-result in existing codebase
  • Converting try/catch blocks to Result types
  • Replacing thrown exceptions with typed errors
  • Migrating Promise-based code to Result.tryPromise
  • Introducing railway-oriented programming patterns

Migration Strategy

1. Start at Boundaries

Begin migration at I/O boundaries (API calls, DB queries, file ops) and work inward. Don't attempt full-codebase migration at once.

2. Identify Error Categories

Before migrating, categorize errors in target code:

CategoryExampleMigration Target
Domain errorsNotFound, ValidationTaggedError + Result.err
InfrastructureNetwork, DB connectionResult.tryPromise + TaggedError
Bugs/defectsnull deref, type errorLet throw (becomes Panic if in Result callback)

3. Migration Order

  1. Define TaggedError classes for domain errors
  2. Wrap throwing functions with Result.try/tryPromise
  3. Convert imperative error checks to Result chains
  4. Refactor callbacks to generator composition

Pattern Transformations

Try/Catch to Result.try

typescript
1// BEFORE 2function parseConfig(json: string): Config { 3 try { 4 return JSON.parse(json); 5 } catch (e) { 6 throw new ParseError(e); 7 } 8} 9 10// AFTER 11function parseConfig(json: string): Result<Config, ParseError> { 12 return Result.try({ 13 try: () => JSON.parse(json) as Config, 14 catch: (e) => new ParseError({ cause: e, message: `Parse failed: ${e}` }), 15 }); 16}

Async/Await to Result.tryPromise

typescript
1// BEFORE 2async function fetchUser(id: string): Promise<User> { 3 const res = await fetch(`/api/users/${id}`); 4 if (!res.ok) throw new ApiError(res.status); 5 return res.json(); 6} 7 8// AFTER 9async function fetchUser(id: string): Promise<Result<User, ApiError | UnhandledException>> { 10 return Result.tryPromise({ 11 try: async () => { 12 const res = await fetch(`/api/users/${id}`); 13 if (!res.ok) throw new ApiError({ status: res.status, message: `API ${res.status}` }); 14 return res.json() as Promise<User>; 15 }, 16 catch: (e) => (e instanceof ApiError ? e : new UnhandledException({ cause: e })), 17 }); 18}

Null Checks to Result

typescript
1// BEFORE 2function findUser(id: string): User | null { 3 return users.find((u) => u.id === id) ?? null; 4} 5// Caller must check: if (user === null) ... 6 7// AFTER 8function findUser(id: string): Result<User, NotFoundError> { 9 const user = users.find((u) => u.id === id); 10 return user 11 ? Result.ok(user) 12 : Result.err(new NotFoundError({ id, message: `User ${id} not found` })); 13} 14// Caller: yield* findUser(id) in Result.gen, or .match()

Callback Hell to Generator

typescript
1// BEFORE 2async function processOrder(orderId: string) { 3 try { 4 const order = await fetchOrder(orderId); 5 if (!order) throw new NotFoundError(orderId); 6 const validated = validateOrder(order); 7 if (!validated.ok) throw new ValidationError(validated.errors); 8 const result = await submitOrder(validated.data); 9 return result; 10 } catch (e) { 11 if (e instanceof NotFoundError) return { error: "not_found" }; 12 if (e instanceof ValidationError) return { error: "invalid" }; 13 throw e; 14 } 15} 16 17// AFTER 18async function processOrder(orderId: string): Promise<Result<OrderResult, OrderError>> { 19 return Result.gen(async function* () { 20 const order = yield* Result.await(fetchOrder(orderId)); 21 const validated = yield* validateOrder(order); 22 const result = yield* Result.await(submitOrder(validated)); 23 return Result.ok(result); 24 }); 25} 26// Error type is union of all yielded errors

Defining TaggedErrors

See references/tagged-errors.md for TaggedError patterns.

Workflow

  1. Check for source reference: Look for opensrc/ directory - if present, read the better-result source code for implementation details and patterns
  2. Audit: Find try/catch, Promise.catch, thrown errors in target module
  3. Define errors: Create TaggedError classes for domain errors
  4. Wrap boundaries: Use Result.try/tryPromise at I/O points
  5. Chain operations: Convert if/else error checks to .andThen or Result.gen
  6. Update signatures: Change return types to Result<T, E>
  7. Update callers: Propagate Result handling up call stack
  8. Test: Verify error paths with .match or type narrowing

Common Pitfalls

  • Over-wrapping: Don't wrap every function. Start at boundaries, propagate inward.
  • Losing error info: Always include cause/context in TaggedError constructors.
  • Mixing paradigms: Once a module returns Result, callers should too (or explicitly .unwrap).
  • Ignoring Panic: Callbacks that throw become Panic. Fix the bug, don't catch Panic.

References

  • TaggedError Patterns - Defining and matching typed errors
  • opensrc/ directory (if present) - Full better-result source code for deeper context

Related Skills

Looking for an alternative to better-result-adopt or building a Categories.community AI Agent? Explore these related open-source MCP Servers.

View All

widget-generator

Logo of f
f

widget-generator is an open-source AI agent skill for creating widget plugins that are injected into prompt feeds on prompts.chat. It supports two rendering modes: standard prompt widgets using default PromptCard styling and custom render widgets built as full React components.

149.6k
0
Design

chat-sdk

Logo of lobehub
lobehub

chat-sdk is a unified TypeScript SDK for building chat bots across multiple platforms, providing a single interface for deploying bot logic.

73.0k
0
Communication

zustand

Logo of lobehub
lobehub

The ultimate space for work and life — to find, build, and collaborate with agent teammates that grow with you. We are taking agent harness to the next level — enabling multi-agent collaboration, effortless agent team design, and introducing agents as the unit of work interaction.

72.8k
0
Communication

data-fetching

Logo of lobehub
lobehub

The ultimate space for work and life — to find, build, and collaborate with agent teammates that grow with you. We are taking agent harness to the next level — enabling multi-agent collaboration, effortless agent team design, and introducing agents as the unit of work interaction.

72.8k
0
Communication