feat(infra): point empty catch rejections at the error-handling guidance

This commit is contained in:
turtle1999 authored and Turtle committed 2026-11-11 12:47:01 +08:00
1 parent 4cfd7e0257
commit 9dc86febb6
3 files changed
+11 -1

No files matched your search

@@ -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.
+8
View File
@@ -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}`)
+1 -1
View File
@@ -179,7 +179,7 @@ const gate: InventoryGate<EmptyCatch> = {
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.`,
}