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

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

LegitStack
I’m hoping you guys can give me some general advice and perhaps code examples if you’re feeling up to it. I’m very interested in Elixir,...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
Kagamiiiii
Student &amp; New to elixir. Nice language. I want to convert a english character, e.g. “a”, which is stored in a variable, to it’s asci...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
wernerlaude
In AR this is so simple @articles = current_user.articles How to do in Ecto? def index(conn, _params) do current_user = conn.assig...
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New

Other popular topics Top

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
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
polypush135
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 27727 240
New
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
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
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
AstonJ
by Lance Halvorsen Elixir and Phoenix are generating tremendous excitement as an unbeatable platform for building modern web application...
460 27162 124
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

We're in Beta

About us Mission Statement