Elixir Language Debugging Tips Debugging with IEX.pry/0


Example

Debugging with IEx.pry/0 is quite simple.

  1. require IEx in your module
  2. Find the line of code you want to inspect
  3. Add IEx.pry after the line

Now start your project (e.g. iex -S mix).

When the line with IEx.pry/0 is reached the program will stop and you have the chance to inspect. It is like a breakpoint in a traditional debugger.

When you are finished just type respawn into the console.

require IEx;

defmodule Example do
  def double_sum(x, y) do
    IEx.pry
    hard_work(x, y)
  end

  defp hard_work(x, y) do
    2 * (x + y)
  end
end