onegrx

onegrx

Cannot enter pry prompt with dbg or IEx.pry()

Hello,
I am trying to pry some code and the request continues without entering pry(1)> prompt. I use require IEx; IEx.pry or dbg with iex --dbg pry -S mix phx.server . I can see request to pry in the terminal, but after clicking Y it just continues. It seems the same as in I cannot get IEx.pry() to work correctly, however I use Elixir 1.16.0 with OTP 26 (erlang 26.1.2). Also tested on 1.17-dev with the same result.

The problem has occurred in my project, but I also created a demo Phoenix app with mix phx.new demo and only changed a PageController to:

  def home(conn, _params) do
    # The home page is often custom made,
    # so skip the default app layout.

    conn
    |> foo()
    |> render(:home, layout: false)
  end

  defp foo(conn) do
    "Pry is not working?"
    |> String.split()
    |> Enum.count()
    |> dbg

    conn
  end

When running iex --dbg pry -S mix phx.server the pry console doesn’t show up. However on the other project with Elixir 1.14 it works (dbg was opt-out back then so I just use iex -S mix phx.server). What am I doing wrong?

Marked As Solved

RomanKotov

RomanKotov

Possibly newer versions of Elixir using uniform interface for both pry and iex shells (or even using the same code for both cases). I was not aware of this, and even did not notice it. I agree that it is nice to have a separate prompt for debugger - it helps to distinguish a mode, and less confusing.
But it is not critical for me, as long as debugging-related features work.

It seems that Elixir 1.14 had a prefix for pry. But starting from Elixir 1.15.0, pry does not change it, and uses a default one. The same is with newer versions. The pry prefix was removed in this commit. The part of commit description mentions pry(N) will now be styled as iex(N).

Also Liked

josevalim

josevalim

Creator of Elixir

Recent Erlang versions allow multiline prompts but, to enable it, we no longer can change the prompt on the fly, hence the change.

RomanKotov

RomanKotov

Hi, welcome to Elixirforum!
I tried to reproduce this, but it worked for me.

Steps I tried:

  • Install Elixir 1.16.0-otp26 via asdf.
  • Install Erlang 26.1.2 via asdf.
  • Create project via mix phx.new demo --no-ecto. Did not want to set up the database. I have phx.new installer for Phoenix 1.7.10.
  • Added .tool-versions file to the root of demo project with relevant versions of Elixir and Erlang.
  • Installed dependencies.
  • Updated the code for lib/demo_web/controllers/page_controller.ex with your example.
  • Started the server with iex --dbg pry -S mix phx.server.
  • Visited http://localhost:4000, and reached a breakpoint. It worked for both dbg and require IEx; IEx.pry.

Tested on macOS Sonoma 14.4.1.

Can you try to reproduce the same issue on the other device?
Possibly via an Elixir Docker (Podman) container. If it works there, then possibly something is with your local environment.

I remember it was an similar issue with Elixir 1.15.0 and OTP 25, but it is already resolved.

RomanKotov

RomanKotov

Have tested your code on MacOS Sonoma 14.4.1 on MacMini 2018, Intel based.
It worked for me.

What I have tried:

  • Cloned a repo
  • Installed dependencies
  • Started the app with iex --dbg pry -S mix phx.server
  • Visited http://localhost:4000/ and reached a breakpoint.
  • Stopped the application.
  • Added another breakpoint (2) with require IEx; IEx.pry().
  • Started the application with iex -S mix phx.server and refreshed a page in browser.
  • Debugger stopped at breakpoint (2).

As I remember, --dbg pry argument appeared at Elixir 1.15.0. dbg macro does not stop at breakpoint without it (though it stopped in Elixir 1.14.x). I mainly use dbg for debug tracing in the code and require IEx; IEx.pry() to set breakpoints (as it always worked).

I think it is not related to the OS, but to the local environment.
Can you try to run your code inside the Docker/Podman?

  • Start an Elixir container, something like docker run --rm -it -p 127.0.0.1:4000:4000 elixir:1.16 bash
  • Install a git there apt update && apt install git
  • Clone your repo git clone https://github.com/onegrx/pry.git
  • Visit a repo and install dependencies cd pry; mix deps.get
  • Possibly you will want to comment a repo in your configuration. There is no Postgres inside a container. It is not relevant by the way.
  • Start the application via iex --dbg pry -S mix phx.server .
  • Visit http://localhost:4000 in your browser.

I have written previous commands just to show steps and have not tested them (have not installed Docker on my machine and deleted Podman some time ago). Possibly you will need to install extra dependencies (like PostgreSQL). It should be easy to find solutions for them in the Internet.

I have recently got an interesting error. I played with Erlang and added custom configuration file for it. I have printed a message inside it. When I installed a dependency (erlexec) - the installation process somehow took this message and tried to install dependencies through it. It failed, and I had to update my configuration files. Possibly something similar is in your case, so I suggested to try the same on the other machine.

Erlang looks for configuration in a couple of locations:

  • ~/.erlang
  • ~/Library/Application Support/erlang/.erlang
  • IEX uses ~/.iex.exs
  • Environment variable ERL_AFLAGS (you can see its contents via echo $ERL_AFLAGS). I have added this variable to store shell history.

If breakpoints will work inside the Docker/Podman container, then something is with your local configuration.

Last Post!

RomanKotov

RomanKotov

Thank you for the answer.

I wanted to port a CRDT library to BEAM VM. It should allow to sync data between different tech stacks and provide offline-first features. But needed to test if it will work fine with immutable structures. It should be a side project, so I wanted to learn Erlang through writing a POC implementation.

I do a debugger-driven development (at least if language allows it). I write code in shell and debug it there. But I was not able to find a CLI debugger for Erlang. There are some libraries, but I was not able to fit them properly into my workflow (missing shell history and lack of auto-completion would decrease my productivity).

I like my iex workflow in Elixir - it is a game-changer. And I miss similar tool for Erlang. I can find how each feature is implemented in OTP :debugger module, so writing a basic CLI should not be a problem. Possibly it is only me who misses CLI debugger.

I digged into how debugger works in Elixir. Possibly Erlang CLI debugger will not give much benefits for it, but I may not be aware of everything. Just wanted to hear your opinion.

Planned to create a simple POC of debugger, just to be more productive with Erlang. I could reach the maintained debugger library with proposals (but it would be rewriting a large part of existing library).

So my main question if it can be useful to Elixir (and other languages in BEAM ecosystem) to have an extensible CLI debugger, or this thing is not worth the effort. I am aware, that there are LSP for both Elixir and Erlang that support DAP protocol and allow debugging in the IDE.

Where Next?

Popular in Questions Top

hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a > b) do {:ok, "a"} end if (a < b) do {:ok, b} end if (a == b) do {:ok, "equa...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New

Other popular topics Top

baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New

We're in Beta

About us Mission Statement