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 從公開儲存庫中收錄這些內容。

檢舉或申請下架