SECURITY WARNING: Never run commands you don't understand. Always review code before execution. Use at your own risk.
Elixir New Added 19 September 2026

Elixir: (MatchError) no match of right hand side value: {:error, :enoent}

A pattern match assumed the happy path and the function returned the error tuple instead, so the process crashed at the assignment rather than at the failure. The value in the message is the whole answer: it names both what went wrong and which call produced it.

Quick fix

Read the commands before running them. Anything that restarts a service, deletes data or changes permissions should be tried on a non-production system first.

Quick fix
# The crash: {:ok, body} cannot match {:error, :enoent}
{:ok, body} = File.read(path)

# Handle both shapes where the decision belongs
case File.read(path) do
  {:ok, body} -> parse(body)
  {:error, :enoent} -> {:error, "no file at #{path}"}
  {:error, reason} -> {:error, :file.format_error(reason)}
end

# with chains several calls and passes the unmatched value through untouched
with {:ok, body} <- File.read(path),
     {:ok, json} <- Jason.decode(body) do
  {:ok, json}
else
  {:error, reason} -> {:error, reason}
end

# The bang variants raise an exception that names the file, which beats a MatchError
body = File.read!(path)

# Deliberate assertions are fine in scripts and tests: crashing early is the point

How to diagnose Elixir errors

Elixir errors are shaped by the actor model: a GenServer.call timeout does not mean the server crashed, it means the server was busy for longer than the caller was willing to wait. The right question is usually "what is that process doing?" rather than "why did the call fail?". Because supervisors restart failed processes automatically, transient errors can also hide in the logs while the system appears healthy.

If the quick fix above does not resolve it, work through these steps. They apply to this whole class of error, not just to this one message, which is usually what saves the time.

  1. Attach to a running node with iex --remsh and inspect the process: Process.info(pid, :message_queue_len). A growing mailbox means the process is the bottleneck.
  2. Use :observer.start() to see the supervision tree, process memory and message queues visually.
  3. Move long-running work out of handle_call. Use handle_cast, a Task, or a dedicated pool so the GenServer stays responsive.
  4. Check restart intensity. A supervisor that exceeds max_restarts takes down its own supervisor, producing a cascade that looks like an unrelated failure at the top.
  5. For compile errors in dependencies, run mix deps.compile --force and check that any required native toolchain (make, gcc, erlang headers) is installed.

Tools worth reaching for

  • :observer.start()
  • iex --remsh
  • Process.info/2
  • mix deps.tree
  • :recon

Authoritative references

Primary documentation for this error, worth reading before applying any fix in production.

hexdocs.pm hexdocs.pm

Related Elixir errors

See all 12 Elixir errors →

Browse other categories

Something missing or wrong?

This entry is maintained by hand. If the fix is out of date, incomplete, or you have a better one, email a correction and it will be reviewed.