Skip to content
Latchkey

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/1

Common 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

  1. Read the "following arguments were given" block.
  2. Add the missing clause or relax a guard.
  3. 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

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →