Every failure path leaves a trace in the logs, and no failure is invented without checking what the API actually returns. Prompted by diigo-cache's password-manager save reporting "not saved" on success (CredentialsContainer.store() resolves with undefined). Generated-by: Claude Opus 5.5
2.0 KiB
2.0 KiB
name: silent-failures-are-evil description: No silent failures — use when writing or reviewing error handling: catch blocks, promise rejections, fallbacks for unsupported features, or any branch that treats a result as "didn't work"; when a UI shows a failure with nothing logged; when someone says "silent failure". Every failure path leaves a trace in the logs, and no failure is invented without checking what the API actually returns.
Silent failures are evil
A failure nobody can see is a failure nobody can fix. Every failure path must leave a trace.
the rules
- Log every failure path: a caught exception, a rejected promise, a
falsy result treated as "didn't work", an unsupported-feature
fallback. Changing a label on screen is not enough — log it, with an
eventtag for grepping, and no secrets (no keys, cookies, header or param values). - Don't invent failures. Before branching on a result, check what the API actually returns (the spec or MDN, not a guess). A success misreported as failure is as bad as a failure reported as nothing.
- Say only what you know. When an API can't tell you the outcome, report what it did tell you ("offered", not "saved").
- Make it testable. Pass the logger in (see ocap-discipline) so a test can assert that the failure path logged; a discovered silent failure is a goof that owes a test (lazy-tdd).
the goof that prompted this
diigo-cache's password-manager save button said "not saved", with
nothing in the console. The code read c ? "saved" : "not saved" on the
result of CredentialsContainer.store(),
which resolves with undefined per spec — even on success. So every
save was reported as a failure, silently. The fix
(capsite/diigo-cache/src/pm-save.ts) reports "offered", logs every
outcome, and is covered by tests/pm-save.test.ts.