Logs the error and carries on
Logs the error and carries on. Logs the error and carries on as if it worked. The caller gets no signal that this failed.
This is how the comment reads inline, under the flagged line.
Why it matters
Logging an error and continuing means the caller thinks it worked. The log line is the only witness, and nobody reads it in time.
What to do
Rethrow after logging, or return a result the caller has to check.
Examples
try {
await charge(card);
} catch (e) {
console.error(e);
}await charge(card); // the caller shows the decline
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) {
console.error(e);
}
src/app.py
try:
go()
except ValueError as e:
logger.warning(e)
Left alone
try {
go();
} catch (e) {
console.error(e);
throw 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": [
"log-and-continue"
],
"severity": {
"log-and-continue": "low"
}
}
}