Empty catch
Empty catch. This catch block is empty, so the error disappears. Nothing will tell you this failed.
This is how the comment reads inline, under the flagged line.
Why it matters
An empty catch makes every failure look like success. The bug surfaces later and far away, with no trace of the cause.
What to do
Let the error propagate, or handle the specific error you expect and rethrow the rest.
Examples
try {
await save(order);
} catch {}await save(order);
What it catches
It reads the shape of the code: functions, blocks, loops and calls. Languages: TypeScript and JavaScript, Python. Scope: All files. These cases are the rule's own tests: the first set must be flagged and the second must not.
Flagged
try {
go();
} catch (e) {}
src/app.py
try:
go()
except ValueError:
pass
Left alone
try {
go();
} catch (e) {
throw new Error('save failed', { cause: e });
}
Research
Empty catch, `except: pass`, `.catch(() => {})`, and catch blocks that only log. The failure disappears from the person who could fix it.
- Ruff: try-except-pass
- Taxonomy: swallowed exceptions
- skill: code-review
Turn it off or change it
In a config file for the CLI, or in the API's rules field:
{
"rules": {
"disable": [
"empty-catch"
],
"severity": {
"empty-catch": "low"
}
}
}