Metastatic.Analysis.BusinessLogic.SwallowingException
(Metastatic v0.10.4)
View Source
Detects exception handling that swallows exceptions without logging or re-raising.
This analyzer identifies try/catch/rescue blocks that catch exceptions but don't log them or re-raise them, which hides errors and makes debugging difficult.
Cross-Language Applicability
This is a universal anti-pattern in all languages with exception handling:
- Python:
try/exceptthat silently catches - JavaScript:
try/catchwithout logging - Elixir:
try/rescuewithout logging or re-raising - Java/C#:
try/catchwith empty catch block - Ruby:
begin/rescuewithout handling - Go: Ignoring error returns (similar concept)
Examples
Bad (Python)
try:
risky_operation()
except Exception:
pass # Silent failure!Good (Python)
try:
risky_operation()
except Exception as e:
logger.error(f"Operation failed: {e}")
raiseBad (Elixir)
try do
risky_operation()
rescue
_ -> :error # Exception hidden!
endGood (Elixir)
try do
risky_operation()
rescue
e ->
Logger.error("Operation failed", error: inspect(e))
:error
endBad (JavaScript)
try {
riskyOperation();
} catch (e) {
return null; // Exception swallowed
}Good (JavaScript)
try {
riskyOperation();
} catch (e) {
console.error('Operation failed:', e);
throw e;
}Detection Strategy
Checks exception_handling nodes for:
- Catch/rescue handlers that don't contain logging calls
- Catch/rescue handlers that don't re-raise the exception
- Empty catch blocks