Today I Learned

hashrocket A Hashrocket project

How to debug in Elixir

If you want to debug an elixir code execution you can use the dbg/2 macro. I was already using that nice macro to show the results on each step of a pipe execution on the logs, but I learned that if we use iex to start phoenix server then the dbg/2 calls will act like adding a breakpoints so we can pry on it. We need to start the server with:

iex -S mix phx.server

As a side note this debugging worked on the elixir 1.14.3 version but I saw that on the latest versions there's a new option to be passed to iex --dbg pry in order to swap the dbg implementation from the fancy IO output to the IEx.pry one.

See More #elixir TILs
Looking for help? At Hashrocket, we 💜 Elixir! From our many Elixir client projects, to sponsoring the Chicago Elixir Meetup, to the source code for this application, we are invested in this community. Contact us today to talk about your Elixir project.