Dap-debug in Emacs can't find debugger.sh, and doesn't seem to be loading projects correctly

Environment

  • Elixir & Erlang versions (elixir --version):
    • Erlang/OTP 25
    • Elixir 1.14.1 (compiled with Erlang/OTP 23)
  • Elixir Language Server version:
    • 0.11.0
  • Operating system:
    • macOS 13.0.1 (22A400)
  • Editor or IDE name (e.g. Emacs/VSCode):
    • Emacs 29
  • Editor Plugin/LSP Client name and version:
    • Emacs lsp-mode/dap-mode

Current behavior

Using dap-mode in elixir, when I attempt to start up dap-debug, it throws an error saying: Searching for program: No such file or directory, debugger.sh

There are no logs in my Messages buffer beyond the one mentioned earlier. There are not messages beyond the startup messages in the lsp-log buffer. elixir-ls, elixir-ls::stderr, and Elixir::Run stderr buffers are empty

I suspect that my emacs config is not putting the lsp-related files where they are expected to be. To deal with that, I updated the dap-register-debug-template to explicitly state where the elixir-ls files are. It looks like this:

(dap-register-debug-template
"Elixir::Phoenix"
(list :type "Elixir"
:task "mix phx.server"
:request "launch"
:dap-server-path '("~/.emacs.d/.cache/lsp/elixir-ls/debugger.sh")
:name "Elixir::Phoenix"))

Upon doing that, it could find debugger.sh, but the project itself fails to find my Repo to run tests, and I get the following error:

Started ElixirLS debugger v0.11.0
Elixir version: "1.14.1 (compiled with Erlang/OTP 23)"
Erlang version: "25"
ElixirLS compiled with Elixir 1.11.4 and erlang 22
(Debugger) Initialization failed because an exception was raised:
    ** (RuntimeError) could not lookup Ecto repo Reel.Repo because it was not started or it does not exist
        (ecto 3.9.2) Elixir.Ecto.Repo.Registry.erl:22: Ecto.Repo.Registry.lookup/1
        (ecto_sql 3.9.1) Elixir.Ecto.Adapters.SQL.Sandbox.erl:572: Ecto.Adapters.SQL.Sandbox.lookup_meta!/1
        (ecto_sql 3.9.1) Elixir.Ecto.Adapters.SQL.Sandbox.erl:458: Ecto.Adapters.SQL.Sandbox.mode/2

This makes me think it isn’t picking up my mix config or something. I am likely doing something wrong, or my emacs config is inadequate; however, I have no idea where to even start. Does anyone have any ideas?

here is my emacs config. The project doesn’t seem to matter. I have this problem with a startup hello-world. Even suggestions on how to troubleshoot would be appreciated. Thanks.

Expected behavior

I expect the debugger and to be able to debug my project.

The loneliness of emacs…

Disclaimer: I do not use dap-mode or lsp-mode

If it cannot find your current project folder, then I think that’s due to a missing config setting that states where the current directory is.

I may be wrong, but it seems like there are two ways to go about this:

  1. you can define your own template, or
  2. you can use the one that comes with dap mode with (require 'dap-elixir)

Some sleuthing around on github reveals what someone did when they defined their own template
The :cwd is set to the default-directory or the absolute path to the current buffer file.

The initial template defines it as nil, but they later load it in when they start dap-mode with the above function.

The alternative is for you to just do (require 'dap-elixir) from the dap-mode package, which is what spacemacs does and doom emacs

Hopefully this helps :slight_smile:

Ok, that wasn’t what it was, but honestly, just knowing someone was trying to help gave me the energy to keep poking at it. Thanks so much.

What was happening is it was launching, but it wasn’t starting up my apps… hence the error saying my Repo app wasn’t started. It’s amazing how error messages never make any sense to me until after I figure out what was happening.

Anyway, here is the fix:

(dap-register-debug-template
"Elixir Debug"
(list :type "Elixir"
      :cwd nil
      :request "launch"
      :program nil
      :name "Elixir Debug"
      :startApps t
      :dap-server-path '("~/.emacs.d/.cache/lsp/elixir-ls/debugger.sh")))

To get this config, I ran (dap-debug-edit-template) per these instructions by running M-: and typing (dap-debug-edit-template) in Emacs, which opened up a buffer containing this:

(dap-register-debug-template
  "Elixir::Run"
  (list :type "Elixir"
        :cwd nil
        :request "launch"
        :program nil
        :name "Elixir::Run"))

I then modified that by changing the template name and :name from Elixir::Run to Elixir Debug because I wanted the names to mean something to me. Then I added :startApps t to start the apps per these instructions, and :dap-server-path '("~/.emacs.d/.cache/lsp/elixir-ls/debugger.sh") to set my DAP server path to where straight puts it per my previous findings when I first posted.

Once that was done, it worked. Then I added it to my emacs config to load when elixir mode loads up, which can be seen here

I also added an example config for debugging a single test in case anyone finds that useful. It can be seen here. I got the idea from these docs

Now, when I am working on something, I can run M-x dap-hydra to open up my debug menu, hit bb to toggle a breakpoint, hit dd to start the debugger, choose Elixir Debug from the list, and I have a working debugger.

Anyway, thanks for the help @100phlecs!

2 Likes

thank you!