H

handling-failures

by @riekeltv
4.6(120)

此技能用于编写或修改任何错误路径、捕获块、回退、默认值、重试或降级模式时,强制实施“不静默吞掉”和“大声失败”纪律。它确保每个失败路径都明确记录日志,并选择重抛、返回类型化错误或进入文档化的降级模式,从而避免静默的错误输出,让故障可发现、可诊断、可修复,提升代码质量与系统稳定性。

error-handlingfail-loudcode-qualityresilienceobservabilityGitHub
安装方式
npx skills add https://github.com/riekelt/principal-engineer --skill handling-failures
compare_arrows

Before / After 效果对比

1 组
使用前

在没有这个技能之前,开发者在处理异常时经常直接捕获后继续运行或返回默认值,导致错误被静默吞掉。生产环境出现故障时,日志中缺乏关键线索,工程师往往需要花费大量时间翻阅代码和日志才能定位根因。

使用后

此技能强制每个失败路径都清晰可见,捕获后必须记录日志并选择重抛、类型化返回或明示降级。当故障发生时,日志中直接呈现错误原因和上下文,工程师能快速定位到具体代码行,大幅缩短排查时间。

SKILL.md

Handling failures

REQUIRED BACKGROUND: the principal-engineering skill.

Overview

A swallowed error is a bug with its evidence destroyed. Core contract: every failure path does exactly one of three things, and all three are loud. The system that looks healthy while serving wrong data is worse than the one that crashes, because the crash gets fixed today and the silent wrong output gets discovered in an audit.

The contract

Every catch and failure path either:

  1. Logs at WARN or ERROR and rethrows, or
  2. Logs and returns a TYPED failure the caller must handle (a result type, a sealed error, a status the compiler or contract forces downstream code to acknowledge), or
  3. Logs and enters an explicitly documented degraded mode (the degradation is named in the code and its documentation, and something observable says the system is degraded).

Forbidden, no exceptions:

  • Bare catch-and-continue.
  • Catch-and-return-default (empty list, null, zero, cached copy) that masks the failure.
  • ?? fallback and its cousins where the fallback hides that the primary failed. A fallback is acceptable only when the absence is ALSO surfaced loudly elsewhere.

Each of these converts a detectable failure into silent wrong output.

Corollaries

  • A missing required entry fails loud. Something absent from a registry, config, or catalog is a build or startup failure, never a silent default; otherwise the single source quietly becomes optional.
  • Error states are visible. A workflow must not appear healthy while failing; surface the error state in the UI, the metrics, or the logs someone actually watches.
  • Operator-facing remediation is specific. An operator reads the error message mid-incident; "connection failed, check REDIS_URL and whether redis responds to PING" beats "an error occurred" by the length of the outage.
  • Retries are bounded and observable.
  • Replays of side-effecting operations are idempotent, or they multiply the damage: a retry queue replaying charges is how an outage becomes a refund program.
  • Degraded modes have a bound. Skip-and-continue needs the explicit threshold where degradation becomes abort, as a named, operator-tunable constant. The guard must exist; its value is a judgment call to make with the owner, and an unbounded degraded mode is a slow-motion swallow.
  • On failure paths, observability is part of the minimum, not gold-plating. The log line, the counter, and the alert ship with the fix; a failure path without them is the silent swallow with better intentions.

Touching existing swallows

Code you are editing that already swallows: fix it as part of the work, or explicitly flag it as owed with what it hides. Leaving it silently is endorsing it. In review, a NEW silent swallow is an automatic BLOCKER; a pre-existing one you touched and left unflagged is a WARNING against the change.

Common mistakes

  • "It should never happen" as a reason to swallow. Paths that should never happen are exactly the ones that need a loud alarm when they do.
  • Logging at DEBUG and calling it handled. If nobody sees it in production, it is a swallow with extra steps.
  • Catching broad (Exception, catch {}) to handle narrow. The unexpected failure rides in with the expected one and dies silently beside it.
  • A degraded mode nobody documented. Degradation that only the author knows about is an outage the operator cannot diagnose.
  • Making the test pass by defaulting the failure. The test goes green; the defect graduates to production.

用户评价 (0)

发表评价

效果
易用性
文档
兼容性

暂无评价

统计数据

安装量17.1K
评分4.6 / 5.0
版本
更新日期2026年10月23日
对比案例1 组

用户评分

4.6(120)
5
37%
4
43%
3
13%
2
5%
1
2%

为此 Skill 评分

0.0

兼容平台

🤖claude-code

时间线

创建2026年8月30日
最后更新2026年10月23日
🎁 Agent 知识卡片
调研问卷