AlanMcCann

AlanMcCann

Supervisor.start_child error :undef?

I’m having trouble getting Supervisor.start_child to work and I get the following error when running these commands (the supervisor is started automatically. Any help is appreciated. I’m likely missing something simple.

import Supervisor.Spec
sup_pid = sup_pid = Process.whereis(App.SessionSupervisor)
Supervisor.start_child(sup_pid,["a"])

{:error,
   {:EXIT,
    {:undef,
      [{App.Session, :start_link, [["a"]], []},
      {:supervisor, :do_start_child_i, 3, [file: 'supervisor.erl', line: 374]},
      {:supervisor, :handle_call, 3, [file: 'supervisor.erl', line: 399]},
      {:gen_server, :try_handle_call, 4, [file: 'gen_server.erl', line: 629]},
      {:gen_server, :handle_msg, 5, [file: 'gen_server.erl', line: 661]},
      {:proc_lib, :init_p_do_apply, 3, [file: 'proc_lib.erl', line: 240]}]}}}

session_supervisor.ex

defmodule App.SessionSupervisor do
  use Supervisor

  def start_link do
    Supervisor.start_link(__MODULE__, :ok, name: App.SessionSupervisor)
  end

  def init(:ok) do
    children = [worker(App.Session, [], restart: :transient)]
    worker(App.Session, [], restart: :transient)

    supervise(children, strategy: :simple_one_for_one)
  end
end

session.ex

defmodule App.Session do

  use GenServer

  @doc """
  Starts a new session.
  """
  def start_link(uuid, opts \\ []) do
    GenServer.start_link(__MODULE__, %{uuid: uuid})
  end

… rest of the code.

Most Liked Responses

scouten

scouten

Hi Alan, bumped into this just a few hours ago myself. The docs on this are terrible at telling you what you should provide. (Thankfully, that is a rarity!)

In my case, I had printed a start_link/1 function, but I needed to provide a start_link/2 function. Took me a while to get that right.

In your code, in see three different models name prefixes: App, Jaeger, and Jeager. Perhaps this is as simple as a typo?

AlanMcCann

AlanMcCann

Fix found - formatting the params for start_link as

["uuid", []]

vs

"uuid", []

allows it to properly started a linked child process

>iex -S mix
Erlang/OTP 18 [erts-7.3] [source-d2a6d81] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false]

Interactive Elixir (1.3.2) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> sup_pid = Process.whereis(App.SessionSupervisor)
#PID<0.304.0>
iex(2)> Supervisor.count_children(sup_pid)
%{active: 0, specs: 1, supervisors: 0, workers: 0}
iex(3)> {:ok, pid} = Supervisor.start_child(sup_pid, ["uuid", []])
{:ok, #PID<0.311.0>}
iex(4)> Supervisor.count_children(sup_pid)
%{active: 1, specs: 1, supervisors: 0, workers: 1}

Thanks @NobbZ and @scouten for offering good pointers.

Where Next?

Popular in Questions Top

Tee
can someone please explain to me how Enum.reduce works with maps
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
johnnyicon
Hi all, I’ve just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I’m trying to use Postgres...
New
vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
hariharasudhan94
Lets say i have map like this fetching from my database %{"_id" =&gt; #BSON.ObjectId&lt;58eb1a7a9ad169198c3dXXXX&gt;, "email" =&gt; "XXX...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

Other popular topics Top

aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
johnnyicon
Hi all, I’ve just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I’m trying to use Postgres...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
hariharasudhan94
Lets say i have map like this fetching from my database %{"_id" =&gt; #BSON.ObjectId&lt;58eb1a7a9ad169198c3dXXXX&gt;, "email" =&gt; "XXX...
New

We're in Beta

About us Mission Statement