1
votes

I'm simply trying to run a sample Elixir program from Programming Elixir 1.0 and get the following error though the Supervisor docs make it seem like I shouldn't:

What am I doing wrong?

I do iex -S mix and see the error report:

Erlang/OTP 18 [erts-7.2] [source] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false]

=INFO REPORT==== 2-Apr-2016::20:11:46 ===
    application: logger
    exited: stopped
    type: temporary
** (Mix) Could not start application sequence_supervisor: exited in: SequenceSupervisor.start(:normal, [])
    ** (EXIT) an exception was raised:
        ** (MatchError) no match of right hand side value: {:error, {:shutdown, {:failed_to_start_child, Sequence.Server, {:EXIT, {:undef, [{Sequence.Server, :start_link, '{', []}, {:supervisor, :do_start_child, 2, [file: 'supervisor.erl', line: 343]}, {:supervisor, :start_children, 3, [file: 'supervisor.erl', line: 326]}, {:supervisor, :init_children, 2, [file: 'supervisor.erl', line: 292]}, {:gen_server, :init_it, 6, [file: 'gen_server.erl', line: 328]}, {:proc_lib, :init_p_do_apply, 3, [file: 'proc_lib.erl', line: 240]}]}}}}}
            (sequence_supervisor) lib/sequence_supervisor.ex:18: SequenceSupervisor.start/2
            (kernel) application_master.erl:273: :application_master.start_it_old/4
defmodule SequenceSupervisor do
  use Application

  # See http://elixir-lang.org/docs/stable/elixir/Application.html
  # for more information on OTP Applications
  def start(_type, _args) do
    import Supervisor.Spec, warn: false

    children = [
      # Define workers and child supervisors to be supervised
      # worker(SequenceSupervisor.Worker, [arg1, arg2, arg3]),
      worker(SequenceSupervisor.Server, [123])
    ]

    # See http://elixir-lang.org/docs/stable/elixir/Supervisor.html
    # for other strategies and supported options
    opts = [strategy: :one_for_one, name: SequenceSupervisor.Supervisor]
    {:ok, _pid} = Supervisor.start_link(children, opts)
  end
end

directory tree

.
├── _build
│   └── dev
│       └── lib
│           └── sequence_supervisor
│               └── ebin
│                   ├── Elixir.SequenceSupervisor.beam
│                   └── sequence_supervisor.app
├── config
│   └── config.exs
├── lib
│   └── sequence_supervisor.ex
├── mix.exs
├── README.md
└── test
    ├── sequence_supervisor_test.exs
    └── test_helper.exs

sequence_supervisor.ex

defmodule Sequence do
  use Application

  def start(_type, _args) do
    import Supervisor.Spec, warn: false

    children = [
      worker(Sequence.Server, [123])
    ]

    opts = [strategy: :one_for_one, name: Sequence.Supervisor]
    {:ok, _pid} = Supervisor.start_link(children, opts)
  end
end

mix file (mix.exs)

defmodule SequenceSupervisor.Mixfile do
  use Mix.Project

  def project do
    [app: :sequence_supervisor,
     version: "0.0.1",
     elixir: "~> 1.1",
     build_embedded: Mix.env == :prod,
     start_permanent: Mix.env == :prod,
     deps: deps]
  end

  # Configuration for the OTP application
  #
  # Type "mix help compile.app" for more information
  def application do
    [applications: [:logger],
     mod: {SequenceSupervisor, []}]
  end

  # Dependencies can be Hex packages:
  #
  #   {:mydep, "~> 0.3.0"}
  #
  # Or git/path repositories:
  #
  #   {:mydep, git: "https://github.com/elixir-lang/mydep.git", tag: "0.1.0"}
  #
  # Type "mix help deps" for more examples and options
  defp deps do
    []
  end
end
1

1 Answers

5
votes

If you look in the stack trace provided, there's a segment:

{:undef, [{Sequence.Server, :start_link, '{', []

This means that something is attempting to call the start_link function on your Sequence.Server module, but it is an undefined function.

Judging by your directory tree, not only is the start_link function for Sequence.Server undefined, but it looks like the Sequence.Server module itself is undefined. This is probably because you haven't written the code for it yet.

The code for it can be found on the Programming Phoenix companion site.