andrewariley87

andrewariley87

I cannot get IEx.pry() to work correctly

Hello,

I am going through the Phoenix tutorial. I am currently looking at controllers and trying to open a REPL session like I would with pry in Ruby using IEx.pry() in the Phoenix app. I am able to get as far as being asked if I would like to allow and when I enter Y the request just continues.

I am currently using Elixir 1.15.0 and Phoenix 1.7.7

Steps to reproduce:

  1. Insert IEx.pry() in my code:
defmodule HelloWeb.HelloController do
  require IEx
  use HelloWeb, :controller

  def index(conn, _params) do
    IEx.pry()
    render(conn, :index)
  end

  def show(conn, %{"messenger" => messenger}) do
    render(conn, :show, messenger: messenger)
  end
end
  1. Start server with iex -S mix phx.server
  2. Go to the index
  3. Then I get the following:
[info] GET /hello
[debug] Processing with HelloWeb.HelloController.index/2
  Parameters: %{}
  Pipelines: [:browser]
Request to pry #PID<0.517.0> at HelloWeb.HelloController.index/2 (lib/hello_web/controllers/hello_controlller.ex:6)
    3:   use HelloWeb, :controller
    4:
    5:   def index(conn, _params) do
    6:     IEx.pry()
    7:     render(conn, :index)
    8:   end
    9:
Allow? [Yn]
  1. I enter Y
  2. Then the request continues:
Allow? [Yn] Y
[info] Sent 200 in 44443ms
iex(1)> conn

I know I must be doing something wrong. Can someone point me in the right direction?

Most Liked

pdgonzalez872

pdgonzalez872

hi @andrewariley87! Welcome to the community!

So, I agree with you. Seems like IEx was broken in 1.15.x for a little bit, but git bisect told me this commit fixed it: Also handle charlist returns from stdio · elixir-lang/elixir@ed02fa6 · GitHub

It was reported in this issue, but seems like it wasn’t just in tests. Oh, someone mentioned your use case here.

This is kind of a hint as to how folks debug in Elixir land → Folks just don’t stop execution that much. I however, think the “stop execution and poke around” a great tool to have in the bag and one that folks new to our community often use. So when you mentioned it cried I had to take a look at it. IEx and dbg work very well and can/will help you a lot. Your approach is a valid one in this case and you just hit a regression/bug.

So, this fix will be included in a release sometime soon, but you can already use the fix if you used asdf to install elixir (I hope you did): use main-otp-26.

Could you please try that out and report back? Thanks!

(You could also downgrade to 1.14.x and things seem to work fine there. There will be a release soon :), things move fast in the Elixir ecosystem).

Terbium-135

Terbium-135

I gave it a quick try.
Using asdf install elixir main-otp-26 and asdf local elixir main-otp-26
Which gave me:

Erlang/OTP 26 [erts-14.0.2] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [jit]
Elixir 1.16.0-dev (a6439f4) (compiled with Erlang/OTP 26)

Not sure if I ever going to use pryt but adding this to my toolset for sure!

andrewariley87

andrewariley87

Thank you very much the help! I was able to get it to work with main-otp-26 but there were a number of deprecation warnings when using that version(mostly Logger.warn/1 is deprecated). So I ended up using 1.14.5 instead.

Once again thank you for the help!

Where Next?

Popular in Questions Top

Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
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
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
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
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 40165 209
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New

We're in Beta

About us Mission Statement