From 9dc86febb68d8c794f0bdd9ed2c3b0f33eec15bd Mon Sep 17 00:00:00 2001 From: turtle1999 Date: Fri, 6 Nov 2026 16:01:25 +0800 Subject: [PATCH] feat(infra): point empty catch rejections at the error-handling guidance --- .agents/skills/dsh-error-handling/SKILL.md | 2 ++ scripts/verify-empty-catch.spec.ts | 8 ++++++++ scripts/verify-empty-catch.ts | 2 +- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/.agents/skills/dsh-error-handling/SKILL.md b/.agents/skills/dsh-error-handling/SKILL.md index 930c19adfd..fd8e0659f6 100644 --- a/.agents/skills/dsh-error-handling/SKILL.md +++ b/.agents/skills/dsh-error-handling/SKILL.md @@ -34,6 +34,8 @@ For each failure, define handling and reporting owners, containment, and guarant Catching limits exception propagation, not mutations. Only the affected state's owner can establish safe continuation. Otherwise stop dependent work, discard invalid state or instances, or escalate. Logging alone is not recovery. Retries require safe repetition, cancellation, and an explicit owner; finite operations need budgets, while continuing supervision needs lifecycle ownership and observable degradation. +An empty `catch` discards every failure of its `try`, so it is acceptable only when each such failure leaves the owner's state valid and no caller can act on it, such as best-effort cleanup after a primary failure. Keep the `try` to one statement, bind the error to an underscore-prefixed name that states the expected failure, such as `_alreadyGone` (lint requires the prefix on an unused binding; a bare `_` counts as unnamed), and explain in the `catch` block why the state stays valid. When only some failures are acceptable, test `code` or `name` and rethrow the rest; an unconditional discard also reports defects as success. [`verify-empty-catch`](../../../scripts/verify-empty-catch.ts) enforces the form; review checks that the name and reason are true. + ## Localized, actionable, visible reports Every final report needs a readable summary, affected operation, and safe next action. Localize through the receiving application's locale mechanism where one exists; other diagnostics use their existing output language. Keep sensitive internal details out of user-facing text. diff --git a/scripts/verify-empty-catch.spec.ts b/scripts/verify-empty-catch.spec.ts index 493b54b0b8..df36c0ecc2 100644 --- a/scripts/verify-empty-catch.spec.ts +++ b/scripts/verify-empty-catch.spec.ts @@ -151,6 +151,14 @@ describe('empty catch inventory', () => { expect(() => verifyEmptyCatch(root)).toThrow(`${sourcePath}:1 (unnamed, unexplained)`) }) + it('points a rejection at the repository guidance for discarding an error', () => { + const root = fixture() + write(root, sourcePath, broken) + const skillPath = '.agents/skills/dsh-error-handling/SKILL.md' + expect(() => verifyEmptyCatch(root)).toThrow(`(see ${skillPath}#catch-recover-or-stop)`) + expect(readFileSync(join(import.meta.dirname, '..', skillPath), 'utf8')).toMatch(/^## Catch, recover, or stop$/mu) + }) + it('requires pruning retired counts while preserving the remaining clause', () => { const root = fixture() write(root, sourcePath, `${broken}${broken}`) diff --git a/scripts/verify-empty-catch.ts b/scripts/verify-empty-catch.ts index 193eb4f76b..2f8aea694b 100644 --- a/scripts/verify-empty-catch.ts +++ b/scripts/verify-empty-catch.ts @@ -179,7 +179,7 @@ const gate: InventoryGate = { baselinePath: 'scripts/empty-catch.baseline.json', scan: scanEmptyCatches, rejection: 'an empty catch must name the discarded error, state why it needs no handling,' - + ' and keep its try to one statement.', + + ' and keep its try to one statement (see .agents/skills/dsh-error-handling/SKILL.md#catch-recover-or-stop).', describe: finding => `${finding.file}:${String(finding.line)} (${finding.defects.join(', ')})`, success: count => `verify-empty-catch: no new silent catches; ${String(count)} recorded clauses remain.`, }