Metastatic.Analysis.BusinessLogic.MissingErrorHandling
(Metastatic v0.10.4)
View Source
Detects pattern matching on success cases without error handling.
This analyzer identifies code that pattern matches on a success value (typically a tuple or enum variant) without handling the potential error case, which can lead to runtime crashes.
Cross-Language Applicability
This pattern applies to languages with pattern matching and Result/Option types:
- Elixir: Matching
{:ok, value}without handling{:error, reason} - Rust: Unwrapping
Result<T, E>with.unwrap()or matching onlyOk(v) - OCaml/F#: Matching only
Some(v)without handlingNone - Scala: Pattern matching on
SuccesswithoutFailure - Haskell: Pattern matching on
RightwithoutLeft
Examples
Bad (Elixir)
{:ok, user} = Accounts.get_user(id) # Will crash if error returnedGood (Elixir)
case Accounts.get_user(id) do
{:ok, user} -> user
{:error, reason} -> handle_error(reason)
end
# Or with pattern
with {:ok, user} <- Accounts.get_user(id) do
user
endBad (Rust)
let user = get_user(id).unwrap(); // Panics on errorGood (Rust)
let user = match get_user(id) {
Ok(u) => u,
Err(e) => handle_error(e),
};Detection Strategy
Detects pattern matching nodes where:
- The pattern is a success variant (e.g., tuple with
:okatom, or similar markers) - No corresponding error handling pattern exists in the same scope