Handling Failures

作者 riekelte67b7af9ac74无许可证5 个星标收录于 2026年10月8日更新于 2026年10月8日仓库3周前更新

Use when writing or touching any error path, catch block, fallback, default value, retry, or degraded mode - in any language, any repo. Encodes the no-silent-swallows contract and the fail-loud discipline. Use whenever an exception is about to be caught, a null is about to get a default, or a failure could pass unnoticed, even if the goal is "just make it not crash".

AI 生成的概览

为错误路径制定“响亮失败”契约:记录日志、返回类型化失败或进入有文档的降级模式。

功能
该技能为任何语言或代码库中的错误路径行为提供一份书面契约。它要求每个 catch 块、回退、默认值、重试或降级模式必须做到以下之一:记录日志并重新抛出;记录日志并返回调用方必须处理的类型化失败;或记录日志并进入有明确文档说明的降级模式。它还列出了禁止的做法,例如空 catch 后继续执行、捕获后返回默认值,并给出关于可见性、有界重试、幂等重放和可观测性的推论。
适用场景
在编写或修改任何错误路径、catch 块、回退、默认值、重试或降级模式时使用。只要即将捕获异常、即将为 null 设置默认值,或失败可能被忽视,就适用。它也用于审查涉及既有静默吞掉错误的改动。
运行要求
不需要脚本或工具,仅为说明性内容。文中声明需要具备 principal-engineering 技能作为背景。

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. A system that looks healthy while serving wrong data is worse than one that crashes.

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 (named in the code and its documentation, with something observable saying 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.

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.
  • 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. "connection failed, check REDIS_URL and whether redis responds to PING" beats "an error occurred".
  • Retries are bounded and observable.
  • Replays of side-effecting operations are idempotent.
  • 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. 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. Those paths 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 dies silently beside the expected one.
  • A degraded mode nobody documented. Degradation 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.

来源与署名

来源:riekelt/principal-engineer位于plugins/principal-engineer/skills/handling-failures提交e67b7af

许可证: 无许可证

内容归原作者所有。SourceWeft 从公开仓库中收录这些内容。

举报或申请下架