Token导航 LogoToken导航TokenDH.com
研究检索需要联网github未标认证来源可访问clear审计通过

better-result-adopt更好的结果采用

Agent Skill

better-result-adopt 用于查找、检索和筛选相关信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要根据关键词、任务场景或来源线索快速定位候选结果时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

6,847

周安装

277

GitHub Stars

1,436

下载量

2,150
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

3

许可证

MIT

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:better-result-adopt(更好的结果采用)
来源仓库:https://github.com/dmmulroy/better-result
仓库路径:skills/better-result-adopt
安装命令:
npx skills add https://github.com/dmmulroy/better-result --skill better-result-adopt
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。不同来源提供的安装方式可能略有差异;本站展示可直接复制的安装命令,安装前请核对来源页面。

skills.shnpx skills
npx skills add https://github.com/dmmulroy/better-result --skill better-result-adopt

简介

指导如何在现有代码库中逐步迁移至 better-result 错误处理范式。

  • 支持从 try/catch 向 Result.try 转换,并引入 TaggedError 类型定义。
  • 提供模块级迁移路径和错误链式处理的最佳实践参考。
  • 使用前应评估当前项目错误处理结构,制定分阶段迁移计划。
  • 适用宿主包括 Codex、Claude、Cursor、Gemini CLI,接入前应确认版本、权限和运行环境要求。

SKILL.md

better-result Adopt

Adopt better-result incrementally in existing codebases without rewriting everything at once.

When to Use

Use this skill when the user wants to:

  • migrate from try/catch to Result.try or Result.tryPromise
  • replace nullable return values with typed Result<T, E>
  • define domain-specific TaggedError types
  • refactor nested error handling into andThen chains or Result.gen
  • standardize error handling across a service or module

Reading Order

TaskFiles to Read
Adopt better-result in a moduleThis file
Define or review error typesreferences/tagged-errors.md
Inspect library implementation detailsopensrc/ if present

Prerequisites

Before editing code:

  1. Confirm better-result is already installed in the target project.
  2. Check for an opensrc/ directory. If present, read the package source there for current patterns.
  3. Identify the migration scope first: one file, one module, or one boundary layer.

Migration Strategy

1. Start at boundaries

Begin with I/O boundaries and exception-heavy code:

  • HTTP clients
  • database access
  • file system operations
  • parsing and validation
  • framework adapters

Do not convert the whole codebase at once.

2. Classify existing failures

CategoryExamplesTarget shape
Domain errorsnot found, validation, authTaggedError + Result.err
Infrastructure errorsnetwork, DB, file I/OResult.tryPromise + mapped error
Programmer defectsbad assumptions, null derefleave throwing; defects become Panic inside Result callbacks

3. Migrate in this order

  1. Define error types.
  2. Wrap throwing boundaries with Result.try / Result.tryPromise.
  3. Replace null or boolean sentinel returns with Result.
  4. Refactor call sites to propagate Result values.
  5. Collapse nested branching into andThen, mapError, or Result.gen.

Core Transformations

Try/catch → Result.try

function parseConfig(json: string): Result<Config, ParseError> {
  return Result.try({
    try: () => JSON.parse(json) as Config,
    catch: (cause) => new ParseError({ cause, message: `Parse failed: ${cause}` }),
  });
}

Async throws → Result.tryPromise

async function fetchUser(id: string): Promise<Result<User, ApiError | UnhandledException>> {
  return Result.tryPromise({
    try: async () => {
      const res = await fetch(`/api/users/${id}`);
      if (!res.ok) throw new ApiError({ status: res.status, message: `API ${res.status}` });
      return res.json() as Promise<User>;
    },
    catch: (cause) => (cause instanceof ApiError ? cause : new UnhandledException({ cause })),
  });
}

Null sentinel → Result

function findUser(id: string): Result<User, NotFoundError> {
  const user = users.find((candidate) => candidate.id === id);
  return user
    ? Result.ok(user)
    : Result.err(new NotFoundError({ id, message: `User ${id} not found` }));
}

Nested flow → Result.gen

async function processOrder(orderId: string): Promise<Result<OrderResult, OrderError>> {
  return Result.gen(async function* () {
    const order = yield* Result.await(fetchOrder(orderId));
    const validated = yield* validateOrder(order);
    const result = yield* Result.await(submitOrder(validated));
    return Result.ok(result);
  });
}

Execution Workflow

  1. Audit the target module for try, catch, .catch(...), throw, null, undefined, and status-flag error handling.
  2. Define or update TaggedError classes before changing control flow.
  3. Convert boundary functions first and change their signatures to Result<T, E> or Promise<Result<T, E>>.
  4. Update immediate callers so they handle or propagate the new Result.
  5. Where multiple Result-returning steps compose, use Result.gen or andThen.
  6. Preserve error context by keeping cause, IDs, messages, and other structured fields.
  7. Run tests and add coverage for both success and error paths.

Completion Criteria

A migration is complete when:

  • target functions no longer rely on try/catch for expected domain failures
  • nullable or sentinel error returns are replaced with explicit Result values
  • domain failures use typed TaggedError classes
  • callers either propagate Result or explicitly unwrap/match it
  • tests cover at least one success path and one representative error path

Common Pitfalls

  • Over-wrapping everything instead of starting at boundaries
  • Losing original failure context when mapping errors
  • Mixing throw-based and Result-based APIs deep in the same flow
  • Catching Panic instead of fixing the underlying defect

In This Reference

FilePurpose
references/tagged-errors.mdTaggedError patterns, matching, type guards, and examples

If opensrc/ exists, treat it as the source of truth for implementation details and current API behavior.

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

04

需要参考平台分布和安装热度时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

补充不同宿主或平台的使用分布数据

能力 5

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Claude Code

26.96%
按下载量换算580

OpenCode

24.45%
按下载量换算526

Codex

19.2%
按下载量换算413

Cursor

12.14%
按下载量换算261

Gemini CLI

7.74%
按下载量换算166

Antigravity

3.43%
按下载量换算74

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

需要联网

该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。

来源信息

继续浏览同类 Skills