📝 Disallow catch blocks that only log to console and swallow the error.
💼 This rule is enabled in the following configs: 🌐 all, 🏆 best-practices, ✅ recommended.
Disallow catch blocks that only call console.log, console.warn, console.error, or console.debug without rethrowing, returning, or delegating the failure to a real error handler.
LLMs often generate placeholder error handling like catch (error) { console.error(error); }. That looks intentional, but it still swallows the failure: callers do not see an error, control flow continues, and production systems quietly drift into bad state.
This rule focuses on the narrow, high-signal case where a non-empty catch block contains only console logging calls. It deliberately does not overlap with no-empty-catch — truly empty or comment-only blocks belong to that rule.
try {
await processOrder(order);
} catch (error) {
console.error(error);
}
try {
await loadConfig();
} catch (error) {
console.warn("Config failed", error);
console.debug(error);
}try {
await processOrder(order);
} catch (error) {
throw new Error("Failed to process order", { cause: error });
}
try {
return await loadConfig();
} catch (error) {
logger.error("Config load failed", { error });
return null;
}
try {
await publishEvent(event);
} catch (error) {
Sentry.captureException(error);
}
try {
await performWork();
} catch (error) {
console.error(error);
throw error;
}| Catch body contents | Flagged? |
|---|---|
console.error(error) |
✅ Yes |
console.log(error); console.warn("failed", e) |
✅ Yes |
console.error(error); throw error; |
❌ No |
console.error(error); handleError(error); |
❌ No |
handleError(error) |
❌ No |
empty catch {} |
❌ No |
- Logging alone does not change control flow.
- Callers cannot recover because they never learn the operation failed.
- Background tasks can keep running with partial or invalid state.
- The code looks "handled" in review even though the failure was dropped.
The teaching message explains:
- What's wrong — the catch block only logs and swallows the error
- Why — execution continues as if nothing failed
- How to fix — rethrow, return an explicit fallback, or delegate to a real handler such as a logger or error tracker