Elixir "(FunctionClauseError)" in CI
A function was called with arguments that match none of its clauses or guards. Elixir raises FunctionClauseError because there is no head to dispatch to.
What this error means
A test or task crashes with (FunctionClauseError) no function clause matching in Mod.fun/arity, listing the attempted clauses and the actual arguments. It is deterministic given the input.
mix
** (FunctionClauseError) no function clause matching in MyApp.parse/1
The following arguments were given to MyApp.parse/1:
# 1
:unexpected
(my_app 0.1.0) lib/my_app.ex:5: MyApp.parse/1Common causes
Unhandled input shape
The argument is a value (or pattern) no clause covers - a new variant, a nil, or an unexpected tuple shape.
Guard excludes the value
Every clause has a guard, and the argument satisfies none of them, so dispatch fails.
How to fix it
Add a catch-all or handle the shape
Add a clause that handles the unmatched input explicitly.
my_app.ex
def parse(:unexpected), do: {:error, :unexpected}
def parse(value) when is_binary(value), do: {:ok, value}Inspect the actual argument
- Read the "following arguments were given" block.
- Add the missing clause or relax a guard.
- Validate input at the boundary before dispatch.
How to prevent it
- Cover all expected input shapes with clauses.
- Validate external input before pattern matching.
- Add tests for edge-case arguments.
Related guides
Elixir "(UndefinedFunctionError)" in CIFix the Elixir "(UndefinedFunctionError) function X is undefined or private" runtime error in CI - a called f…
Elixir "(KeyError) key not found" in CIFix the Elixir "(KeyError) key :x not found in: %{...}" error in CI when code accesses a map or struct key th…
sbt test "TestFailedException" in CIFix sbt test failures reporting "org.scalatest.exceptions.TestFailedException" in CI - an assertion did not h…