Credence.Pattern.NoUnnecessaryCatchAllRaise
(credence v0.4.0)
Copy Markdown
Detects function clauses where every argument is a wildcard and the
body does nothing but raise.
Why this matters
Elixir's FunctionClauseError is a first-class debugging tool. When
no clause matches, the runtime raises an error that names the function
and shows the exact arguments that failed to match. A hand-written
catch-all that raises a generic error actively degrades that signal:
# Bad — hides the actual arguments from the error
def missing_number(_), do: raise(ArgumentError, "expected a list")
# Good — Elixir does this automatically, with better diagnostics
# (just remove the catch-all clause entirely)LLMs generate these defensive catch-alls frequently because their training data includes Python / Java patterns where unhandled cases must be raised explicitly. In Elixir the convention is to let non-matching calls crash naturally.
Flagged patterns
Any def / defp clause where:
- Every argument is a wildcard
_or_name), and - The body consists solely of a
raisecall.
Guarded clauses are not flagged — the guard implies intentional matching logic even if the arguments are wildcards.
Not flagged
- Catch-all clauses that return a value (e.g.
{:error, :invalid}) - Clauses with logic before the raise (logging, cleanup)
- Zero-arity functions
- Clauses with guard expressions
Fix
Removes the unnecessary catch-all clause, letting Elixir's built-in
FunctionClauseError handle unmatched arguments with better diagnostics.