Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Live reload breaks debugging session in elixirLS debugger #133

Open
lukaszsamson opened this issue Jan 9, 2023 · 9 comments
Open

Live reload breaks debugging session in elixirLS debugger #133

lukaszsamson opened this issue Jan 9, 2023 · 9 comments

Comments

@lukaszsamson
Copy link

I know that this most likely not be planned but there are repeated bugs and support requests related to that issue.

elixir-lsp/elixir-ls#797
elixir-lsp/elixir-ls#798

There are 2 problems when phoenix is run under elixirLS debugger

  1. The code reloader (https://github.com/phoenixframework/phoenix/blob/master/lib/phoenix/code_reloader/server.ex) is purging and reloading modules on the fly with no regard for the ongoing debug session. The reloaded modules are not properly interpreted via erlang debugger.
  2. It is messing with IO interception. Debug Adapter Protocol has strict requirements on stdout IO. All standard IO needs to be sent as JSONRPC protocol messages.
@josevalim
Copy link
Member

This is tricky because I can’t come with good suggestions to address this. At best we could block the code reloader but I am not sure that would help either.

@CharlesIrvineKC
Copy link

Thought I would add a note specifying the impact of and work around for the problem. Basically, any time code is changed while in a debugging session, the Elixir compiler will likely throw spurious (false positive) errors. The work around is to bounce the debugger. This clears the problem and allows debugging to continue.

@josevalim
Copy link
Member

@lukaszsamson if you can reproduce it we should do a pairing session :)

@CharlesIrvineKC
Copy link

CharlesIrvineKC commented Jan 10, 2023

There may be multiple error paths, but here is one that comes up often. To reproduce in vscode:

  1. Create a new Phoenix 1.6 app: "mix phx.new hello".
  2. Create a launch config. Add: "task": "phx.server".
  3. In "page_controller.ex" add a break point to line 5.
  4. Execute: Run/Start Debugging.
  5. Go to "localhost:4000" to trigger the breakpoint. Continue past the breakpoint.
  6. Insert "IO.inspect(conn)" above line 5.
  7. Reset breakpoint to new line 5 and refresh "localhost:4000".
  8. The following error occurs:
Compiling 1 file (.ex)

== Compilation error in file lib/hello_web/controllers/page_controller.ex ==
** (UndefinedFunctionError) function HelloWeb.__using__/1 is undefined or private. However there is a macro with the same name and arity. Be sure to require HelloWeb if you intend to invoke this macro
    (hello 0.1.0) HelloWeb.__using__(:controller)
    lib/hello_web/controllers/page_controller.ex:2: (module)
    (elixir 1.14.2) lib/kernel/parallel_compiler.ex:346: anonymous fn/5 in Kernel.ParallelCompiler.spawn_workers/7

@coreyvan
Copy link

coreyvan commented Aug 7, 2024

Is there any update to this issue or other workarounds? This makes the dev experience while debugging (I'm basically always debugging) pretty painful.

@lukaszsamson
Copy link
Author

No. To address it either phoenix should check if modules are interpreted and call :int.ni after it recompiles or emit some event that the debug adapter can listen for and reinterpret. Probably breakpoints also need to be reset after that. A workaround could be to periodically reinterpret all modules in the VM that match launch config settings.

@CharlesIrvineKC
Copy link

My impression is that everyone in the Phoenix development community has given up on using a debugger and just use IO.inspect. Coming from a Java background where everyone used a debugger, I struggled for quite a while trying to get debugging working with Phoenix and ElixirLS and finally gave up and gave in to using IO.inspect. It's a shame I think. A lot of people would be very happy to be able to use the ElixirLS debugger with Phoenix.

@morganhein
Copy link

Ya this is a shame. I have been trying to audit phoenix and see if I should propose we switch to it for some things at the company I work for, but this is a hard blocker. I really love this ecosystem but being unable to use the tools like we're accustomed and requiring console logging is a non-starter.

That being said, thank you all that have worked on these projects and gotten things this far. Hopefully this gets fixed in the future, and then I'll revisit.

@CharlesIrvineKC
Copy link

I did a post for this on the forum. Let's see if anyone responds.

https://elixirforum.com/t/source-level-debugging-for-phoenix-and-phoenix-liveview-apps/65400

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants