How do you debug failing supervisor in iex?

I’ve been learning Elixir for the past 2 weeks, and decided to write some “real” project. I already have a supervisor tree setup, but when I run MyStuff.Supervisor.start_link and for example, there’s some Sup implementation missing start_link method the iex session just restarts without any message.

How it looks

iex(1)> import_file "repr.exs"
iex(2)> Reproduce.run
Interactive Elixir (1.17.1) - press Ctrl+C to exit (type h() ENTER for help)
iex(2)> Reproduce.run
Interactive Elixir (1.17.1) - press Ctrl+C to exit (type h() ENTER for help)
iex(2)> 

repr.exs

defmodule MyTask do
  use Task
  # NOTE: missing start_link
end

defmodule Reproduce do
  def run() do
    Supervisor.start_link([MyTask], strategy: :one_for_one)
  end
end

So I thought the reason is start_link crashin the iex session, but when I start the run function inside spawn() it still does not show output.

1 Like

https://hexdocs.pm/logger/Logger.html#module-boot-configuration

Turn the OTP and SASL reports on and you should get something.

Enabling handle_otp_reports and handle_sasl_reports does not produce any output

iex(1)> Logger.configure handle_otp_reports: true,
...(1)>   handle_sasl_reports: true, level: :all
:ok
iex(2)> import_file "repr.exs"
...
iex(3)> Reproduce.run

Interactive Elixir (1.17.1) - press Ctrl+C to exit (type h() ENTER for help)
iex(3)> Reproduce.run

Interactive Elixir (1.17.1) - press Ctrl+C to exit (type h() ENTER for help)
iex(3)> 

Huh. I think you may have found a bug. Here’s an IEx session from 1.15.7:

Erlang/OTP 25 [erts-13.2.2.5] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [jit:ns]

Interactive Elixir (1.15.7) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> import_file "repr.exs"
{:module, Reproduce,
 <<70, 79, 82, 49, 0, 0, 5, 196, 66, 69, 65, 77, 65, 116, 85, 56, 0, 0, 0, 200,
   0, 0, 0, 19, 16, 69, 108, 105, 120, 105, 114, 46, 82, 101, 112, 114, 111,
   100, 117, 99, 101, 8, 95, 95, 105, 110, 102, ...>>, {:run, 0}}
iex(2)> Reproduce.run()
** (EXIT from #PID<0.106.0>) shell process exited with reason: shutdown: failed to start child: MyTask
    ** (EXIT) an exception was raised:
        ** (UndefinedFunctionError) function MyTask.start_link/1 is undefined or private
            MyTask.start_link([])
            (stdlib 4.3.1.3) supervisor.erl:420: :supervisor.do_start_child_i/3
            (stdlib 4.3.1.3) supervisor.erl:406: :supervisor.do_start_child/2
            (stdlib 4.3.1.3) supervisor.erl:390: anonymous fn/3 in :supervisor.start_children/2
            (stdlib 4.3.1.3) supervisor.erl:1256: :supervisor.children_map/4
            (stdlib 4.3.1.3) supervisor.erl:350: :supervisor.init_children/2
            (stdlib 4.3.1.3) gen_server.erl:851: :gen_server.init_it/2
            (stdlib 4.3.1.3) gen_server.erl:814: :gen_server.init_it/6

Interactive Elixir (1.15.7) - press Ctrl+C to exit (type h() ENTER for help)
iex(2)> 

But in 1.17.2:

Erlang/OTP 26 [erts-14.2.5.1] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [jit:ns]

Interactive Elixir (1.17.2) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> Application.ensure_all_started(:sasl)
{:ok, [:sasl]}
iex(2)> import_file("repr.exs")
{:module, Reproduce,
 <<70, 79, 82, 49, 0, 0, 5, 160, 66, 69, 65, 77, 65, 116, 85, 56, 0, 0, 0, 200,
   0, 0, 0, 19, 16, 69, 108, 105, 120, 105, 114, 46, 82, 101, 112, 114, 111,
   100, 117, 99, 101, 8, 95, 95, 105, 110, 102, ...>>, {:run, 0}}
iex(3)> Reproduce.run()

Interactive Elixir (1.17.2) - press Ctrl+C to exit (type h() ENTER for help)
iex(3)> require Logger
Logger
iex(4)> Logger.warning("test")

06:13:08.957 [warning] test
:ok
iex(5)> Reproduce.run()

Interactive Elixir (1.17.2) - press Ctrl+C to exit (type h() ENTER for help)
iex(5)> 

I see. I’ll test multiple versions to confirm and then report the bug.

Glad to hear it’s just a bug. It was really frustrating, writing an app without any error messages.

Here’s the issue Starting failing supervisor in IEx crashes session · Issue #13745 · elixir-lang/elixir · GitHub