Metastatic.Analysis.BusinessLogic.SilentErrorCase
(Metastatic v0.10.4)
View Source
Detects conditional statements that only handle the success case.
This analyzer identifies conditionals where only the success/truthy branch is handled without a corresponding error/falsy branch or catch-all, potentially leading to silent failures.
Cross-Language Applicability
This is a universal pattern that applies to all languages with conditionals:
- Python:
ifwithoutelsewhen handling error-prone operations - JavaScript:
ifwithoutelsewhen handling promises/results - Elixir:
casewith only{:ok, _}branch - Rust:
matchwith onlyOk(_)branch - Go: Checking only success case without error handling
Examples
Bad (Elixir)
case Accounts.get_user(id) do
{:ok, user} -> user
end
# What happens if error is returned?Good (Elixir)
case Accounts.get_user(id) do
{:ok, user} -> user
{:error, _} -> nil
endBad (Python)
result = get_user(id)
if result.success:
return result.value
# What if not success?Good (Python)
result = get_user(id)
if result.success:
return result.value
else:
return NoneBad (Rust)
match get_user(id) {
Ok(user) => user,
} // Compile error - non-exhaustive matchGood (Rust)
match get_user(id) {
Ok(user) => user,
Err(e) => handle_error(e),
}Detection Strategy
Checks for:
- Conditionals with only a "then" branch (no "else")
- Pattern matching with only success patterns and no catch-all
- Missing error handling paths in multi-branch conditionals