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:
- 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
- Start server with
iex -S mix phx.server
- Go to the index
- 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]
- I enter
Y
- 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?
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).
4 Likes
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!
1 Like
Hey, thanks for the tip! I didn’t know about that branch (just skimmed right over it)!
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!
2 Likes