Change mix run command to task for Debugging

Elixir noob here and apologies in advance if this has already been answered/is really stupid.

Trying to debug open source project strobe audio. https://github.com/strobe-audio:
mix run -e “Peel.scan()” from the command line works.
I’m trying to move this into a mix task so I can use the debugger in VS Code. I can call this function from the task, but it appears the application is not running as I get an error “Peel.Repo is not started, please ensure it is part of your supervision tree”. How can I build the application the same way that mix run does, but from a task? Thanks in advance.

2 Likes

Look in the documentation here:

https://hexdocs.pm/mix/Mix.html#module-aliases

In the section about Aliases. You should be able to create an alias for your mix run command, I believe.

1 Like

run is already a Mix task. Try setting your debug config to something like this:

{
  "type": "mix_task",
  "name": "Peel.scan/0",
  "request": "launch",
  "task": "run",
  "taskArgs": ["-e", "Peel.scan()"],
  "projectDir": "${workspaceRoot}"
}
1 Like

Thanks so much. This is working, however there is something else in ecto.migrate that is causing an exception in the debugger, but not from the terminal. But at least I can start the debugger now.