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

fail-fast快速失败

Agent Skill

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

总安装

824

周安装

34

GitHub Stars

10

下载量

269
CodexClaudeCursorGemini CLI

安装说明

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

GitHub

来源数

3

许可证

MIT

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

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

请帮我安装这个 Agent Skill:fail-fast(快速失败)
来源仓库:https://github.com/yanko-belov/code-craft
仓库路径:skills/fail-fast
安装命令:
npx skills add https://github.com/yanko-belov/code-craft --skill fail-fast
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

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

skills.shnpx skills
npx skills add https://github.com/yanko-belov/code-craft --skill fail-fast

简介

用于查找、检索和筛选相关信息,支持根据关键词快速定位结果。

  • 强调立即失败原则,避免隐藏错误或传播无效状态。
  • 适用于编写错误处理代码时,确保异常可见且处理及时。
  • 安装方式:通过 npx skills add 命令从 GitHub 仓库安装,建议确认权限范围。
  • fail-fast 属于研究检索类 Skill,可作为该场景下的辅助能力补充。

SKILL.md

Fail Fast

Overview

When something goes wrong, fail immediately and visibly.

Don't hide errors with try/catch that returns defaults. Don't let invalid state propagate. Fail at the point of failure, not three layers later with corrupted data.

When to Use

  • Writing error handling code
  • Tempted to catch and return default
  • Adding "defensive" null checks everywhere
  • Wrapping everything in try/catch
  • Returning error objects instead of throwing

The Iron Rule

NEVER hide failures. Fail loud, fail early.

No exceptions:

  • Not for "the app shouldn't crash"
  • Not for "return something rather than throw"
  • Not for "handle errors gracefully"
  • Not for "defensive programming"

Detection: The "Swallow" Smell

If errors disappear silently, you're failing slow:

// ❌ VIOLATION: Hiding failures
async function processPayment(userId: string, amount: number): Promise<PaymentResult> {
  try {
    const user = await getUser(userId);
    if (!user) return { success: false, error: 'User not found' };

    const card = await validateCard(user.cardToken);
    if (!card.valid) return { success: false, error: 'Invalid card' };

    const result = await chargeCard(card, amount);
    if (!result.success) return { success: false, error: 'Payment failed' };

    return { success: true, transactionId: result.id };
  } catch (error) {
    return { success: false, error: 'Internal error' };  // ← SWALLOWED!
  }
}

Problems:

  • Caller doesn't know WHAT failed
  • Stack trace is lost
  • Bugs hide as "internal error"
  • No visibility into actual failures

The Correct Pattern: Fail Fast

Throw at the point of failure. Let errors propagate:

// ✅ CORRECT: Fail fast
async function processPayment(userId: string, amount: number): Promise<Transaction> {
  // Validate early - fail fast on bad input
  if (!userId) throw new ValidationError('userId is required');
  if (amount <= 0) throw new ValidationError('amount must be positive');

  // Let failures propagate - don't swallow
  const user = await getUser(userId);
  if (!user) throw new NotFoundError(`User ${userId} not found`);

  const card = await validateCard(user.cardToken);
  if (!card.valid) throw new PaymentError('Card validation failed', card.errors);

  // This might throw - that's okay! Let it.
  const transaction = await chargeCard(card, amount);

  return transaction;
}

// Caller handles errors appropriately
try {
  const tx = await processPayment(userId, amount);
  res.json({ success: true, transactionId: tx.id });
} catch (error) {
  if (error instanceof ValidationError) {
    res.status(400).json({ error: error.message });
  } else if (error instanceof NotFoundError) {
    res.status(404).json({ error: error.message });
  } else if (error instanceof PaymentError) {
    res.status(402).json({ error: error.message });
  } else {
    // Unknown error - log it, return 500
    logger.error('Payment failed', error);
    res.status(500).json({ error: 'Internal server error' });
  }
}

Why Fail-Slow Is Dangerous

ProblemImpact
Hidden bugsErrors become "it didn't work"
Lost contextStack trace shows catch, not cause
Corrupted stateInvalid data propagates
Debugging nightmareWhere did it actually fail?
Silent data lossOperations fail but app continues

Fail Fast Techniques

1. Validate Early

function createUser(data: unknown): User {
  // Fail IMMEDIATELY on bad input
  if (!data || typeof data !== 'object') {
    throw new ValidationError('Invalid user data');
  }

  const { email, name } = data as Record<string, unknown>;

  if (!email || typeof email !== 'string') {
    throw new ValidationError('Email is required');
  }

  if (!name || typeof name !== 'string') {
    throw new ValidationError('Name is required');
  }

  // Only proceed with valid data
  return new User(email, name);
}

2. Assert Invariants

function withdraw(account: Account, amount: number): void {
  // Assert what must be true
  assert(amount > 0, 'Withdrawal amount must be positive');
  assert(account.balance >= amount, 'Insufficient funds');

  account.balance -= amount;

  // Post-condition check
  assert(account.balance >= 0, 'Balance went negative - invariant violated');
}

3. Use Type System

// ❌ Fail slow: null checks everywhere
function processOrder(order: Order | null): void {
  if (!order) return;  // Silent failure
  // ...
}

// ✅ Fail fast: require valid input
function processOrder(order: Order): void {
  // If order is null, TypeScript catches it
  // If it gets here with null, it will throw - good!
}

Pressure Resistance Protocol

1. "The App Shouldn't Crash"

Pressure: "Users will see errors if we throw"

Response: Users seeing a clear error is better than corrupted data or silent failure.

Action: Throw errors, catch at boundaries (API layer), return appropriate HTTP codes.

2. "Return Something Rather Than Throw"

Pressure: "Returning error objects is more functional"

Response: Error objects are fine IF callers check them. They usually don't.

Action: Throw for unexpected failures. Use Result types only if callers actually handle both cases.

3. "Handle Errors Gracefully"

Pressure: "Graceful = don't throw"

Response: Graceful = appropriate response. Swallowing is not graceful.

Action: Throw, catch at boundary, return meaningful error response.

4. "Defensive Programming"

Pressure: "Defensive code handles all cases"

Response: Defensive = validate early and fail. Not = hide failures.

Action: Validate inputs, assert invariants, throw on violations.

Red Flags - STOP and Reconsider

If you notice ANY of these, refactor:

  • catch (e) {return null;}
  • catch (e) {return {success: false};}
  • if (!x) return; (silent early return)
  • try {} catch {} (empty catch)
  • Returning default values on error
  • "Error: Internal error" (generic catch-all)
  • Logs error but continues execution

All of these mean: Let the error propagate or throw explicitly.

Quick Reference

Fail Slow (Bad)Fail Fast (Good)
catch (e) {return null}catch (e) {throw e}
if (!user) returnif (!user) throw new NotFoundError()
return {success: false}throw new OperationError()
Generic "internal error"Specific error types
Swallow and continuePropagate and handle at boundary

Common Rationalizations (All Invalid)

ExcuseReality
"App shouldn't crash"Clear errors are better than hidden bugs.
"Return instead of throw"Callers ignore return values. Throws can't be ignored.
"Graceful error handling"Swallowing isn't graceful.
"Defensive programming"Defensive = validate and fail, not hide.
"Never let functions crash"Crashing on errors finds bugs.
"User experience"Users prefer "payment failed" over silent failures.

The Bottom Line

Fail fast. Fail loud. Fail at the source.

When errors occur: throw immediately with context. Let errors propagate to boundaries where they can be logged and translated to user-appropriate responses. Never swallow. Never return defaults to hide failure.

适合场景

01

用户想查找某类 Agent Skill 时

02

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

03

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

04

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

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

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

能力 4

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

能力 5

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

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

平台分布

Claude Code

30.24%
按下载量换算81

Codex

25.32%
按下载量换算68

windsurf

15.94%
按下载量换算43

Antigravity

13.76%
按下载量换算37

trae

7.75%
按下载量换算21

OpenCode

3.13%
按下载量换算8

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

需要联网

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

安装前确认

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

来源信息

继续浏览同类 Skills