no-silent-errors
Report catch blocks that do nothing, so an error is never silently swallowed.
Report a catch block that does nothing. An empty handler swallows the error: nothing is logged, nothing is rethrown, and the failure vanishes.
This rule is part of eslint-plugin-maintainability.
Quick Summary
| Aspect | Details |
|---|---|
| Severity | Error (code quality) |
| Auto-Fix | ❌ No |
| Category | Error-handling |
| Suggestions | ✅ Log, handle or rethrow the error |
Rule Details
The rule reports a catch clause whose body holds no statement: an empty block,
or one holding only empty statements (;). Every spelling of the clause counts:
with a binding (catch (err) {}), without one (catch {}), followed by
finally, inside an async function.
A catch block that does anything handles the error and is not reported: it logs it, rethrows it, returns a fallback value, or records a flag for the caller.
Configuration
| Option | Type | Default | Description |
|---|---|---|---|
allowWithComment | boolean | false | Accept an empty catch with an explanatory comment inside the block or within two lines above it |
ignoreInTests | boolean | true | Skip *.test.* / *.spec.* files |
With allowWithComment, a comment counts as an explanation when it uses one of
these words: intentional, expected, ignore, silent, noop / no-op,
by design, known issue, legacy, third-party, framework, library,
not implemented, TODO, FIXME. A comment far above the try, about
something else, explains nothing.
Examples
❌ Incorrect
try {
data = readCache();
} catch (err) {}
try {
await flush();
} catch {
;
}✅ Correct
try {
data = readCache();
} catch (err) {
console.error('cache read failed', err);
}
try {
data = readCache();
} catch {
return null; // a cold cache is a valid state
}
// With { allowWithComment: true }
try {
data = readCache();
} catch {
// intentional: a missing cache file means a cold start
}Configuration Examples
// eslint.config.mjs
export default [
{
rules: {
'maintainability/no-silent-errors': ['error', { allowWithComment: true }],
},
},
];Related Rules
no-missing-error-context- Thrown errors must carry a messageno-unhandled-promise- Promise rejections must be handled
Known False Negatives
The following patterns are not detected:
Promise .catch with an empty handler
Why: the rule inspects catch clauses; .catch(() => {}) is a function
argument, not a clause.
// ❌ NOT DETECTED
save().catch(() => {});Mitigation: give the handler a body that logs or rethrows.
Use this rule
npm install -D oxlint-plugin-maintainability{ "jsPlugins": ["oxlint-plugin-maintainability"], "rules": { "maintainability/no-silent-errors": "error" }}import { defineConfig } from 'vite-plus';export default defineConfig({ lint: { jsPlugins: ['oxlint-plugin-maintainability'], rules: { 'maintainability/no-silent-errors': 'error', }, },});oxlint-plugin-maintainability re-exports eslint-plugin-maintainability/oxlint: the same rules under the same IDs, and no ESLint install. Why oxlint.
Did this rule catch something? Star the repo to get new CWE coverage as we ship it — or follow the AI-code-security benchmarks behind these rules.