"failed to start child" - Supervisor error

Hi,

I am learning the concept of supervisors. I created a separate supervisor for the external API call. But after creating that supervisor, I am unable to start my application. Any idea what is causing this error?

mix phx.server
[notice] Application hello_world exited: HelloWorld.Application.start(:normal, []) returned an error: shutdown: failed to start child: HelloWorld.Parser.Supervisor
    ** (EXIT) already started: #PID<0.439.0>
[notice] Application plug_cowboy exited: :stopped
[notice] Application cowboy_telemetry exited: :stopped
[notice] Application cowboy exited: :stopped
[notice] Application ranch exited: :stopped
[notice] Application cowlib exited: :stopped
[notice] Application httpoison exited: :stopped
[notice] Application hackney exited: :stopped
[notice] Application metrics exited: :stopped
[notice] Application ssl_verify_fun exited: :stopped
[notice] Application parse_trans exited: :stopped
[notice] Application syntax_tools exited: :stopped
[notice] Application certifi exited: :stopped
[notice] Application mimerl exited: :stopped
[notice] Application idna exited: :stopped
[notice] Application unicode_util_compat exited: :stopped
[notice] Application gettext exited: :stopped
[notice] Application expo exited: :stopped
[notice] Application telemetry_poller exited: :stopped
[notice] Application swoosh exited: :stopped
[notice] Application jason exited: :stopped
[notice] Application xmerl exited: :stopped
[notice] Application esbuild exited: :stopped
[notice] Application phoenix_live_dashboard exited: :stopped
[notice] Application telemetry_metrics exited: :stopped
[notice] Application phoenix_live_view exited: :stopped
[notice] Application phoenix_live_reload exited: :stopped
[notice] Application file_system exited: :stopped
[notice] Application phoenix_html exited: :stopped
[notice] Application postgrex exited: :stopped
[notice] Application ecto_sql exited: :stopped
[notice] Application db_connection exited: :stopped
[notice] Application connection exited: :stopped
[notice] Application phoenix_ecto exited: :stopped
[notice] Application ecto exited: :stopped
[notice] Application decimal exited: :stopped
[notice] Application phoenix exited: :stopped
[notice] Application castore exited: :stopped
[notice] Application phoenix_view exited: :stopped
[notice] Application phoenix_template exited: :stopped
[notice] Application phoenix_pubsub exited: :stopped
[notice] Application plug exited: :stopped
[notice] Application telemetry exited: :stopped
[notice] Application plug_crypto exited: :stopped
[notice] Application mime exited: :stopped
[notice] Application eex exited: :stopped
[notice] Application runtime_tools exited: :stopped
** (Mix) Could not start application hello_world: HelloWorld.Application.start(:normal, []) returned an error: shutdown: failed to start child: HelloWorld.Parser.Supervisor
    ** (EXIT) already started: #PID<0.439.0>

Here is my supervsior:

defmodule HelloWorld.Parser.Supervisor do
  alias HelloWorld.Parser

  use Supervisor

  def start_link(opts) do
    Supervisor.start_link(__MODULE__, opts, name: __MODULE__)
  end

  def init(_opts) do
    children = [
      {Task.Supervisor, name: Parser.TaskSupervisor}
    ]

    Supervisor.init(children, strategy: :rest_for_one)
  end
end

and here is my application.ex:

defmodule HelloWorld.Application do
  # See https://hexdocs.pm/elixir/Application.html
  # for more information on OTP Applications
  @moduledoc false

  use Application

  @impl true
  def start(_type, _args) do
    children = [
      # Start a worker by calling: HelloWorld.Worker.start_link(arg)
      # {HelloWorld.Worker, arg}
      HelloWorld.Parser.Supervisor
    ]

    # See https://hexdocs.pm/elixir/Supervisor.html
    # for other strategies and supported options
    opts = [strategy: :one_for_one, name: HelloWorld.Parser.Supervisor]
    HelloWorld.start_link(children, opts)
  end```

Figured out the issue in application.ex:

opts should have HelloWorld.Supervisor rather than HelloWorld.Parser.Supervisor

but after this, when I run mix phx.server - it returns nothing at all. Also, it doesn’t start my server. Help here?

I don’t think that’s it, your supervisor has the latter name. What’s very interesting is that you never use that name in application.ex – but you should. (EDIT: it’s actually used)

I tried following the tutorial here. My supervisor module is like this HelloWorld.Parser.Supervisor and I am using it in application.ex where I assign children. I guess I am missing something

Oh my mistake, yes you are using it. Sorry.