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

nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" =&gt; #BSON.ObjectId&lt;58eb1a7a9ad169198c3dXXXX&gt;, "email" =&gt; ...
New
hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a &gt; b) do {:ok, "a"} end if (a &lt; b) do {:ok, b} end if (a == b) do {:ok, "equa...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
Lily
In templates/appointment/index.html.eex: &lt;%= for appointment &lt;- @appointments do %&gt; &lt;tr&gt; &lt;td&gt;&lt;%= appoi...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
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

Other popular topics Top

minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 54921 245
New
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 42533 114
New

We're in Beta

About us Mission Statement