HelloWorld
HelloWorld

Reputation: 1073

Elixir: There is no process currently associated with the given name

Elixir gives me an error that says that there is something to do with the process names, however, I don't know how I could fix it.

My mix.exs file is as follows:

defmodule Crowller.MixProject do
  use Mix.Project

  def project do
    [
      app: :crowller,
      version: "0.1.0",
      elixir: "~> 1.7",
      start_permanent: Mix.env() == :prod,
      deps: deps()
    ]
  end

  # Run "mix help compile.app" to learn about applications.
  def application do
    [mod: {Crowller.Application, []}]
  end

  # Run "mix help deps" to learn about dependencies.
  defp deps do
    [
      {:poison, "~> 3.1"}, # json library
      {:httpoison, "~> 1.4"}, # json library
    ]
  end
end

This is my Crowller.Application module:

defmodule Crowller.Application do
  use Application
  import Crowller.Data
  import Crowller.Controller

  def start(_, _) do
    key_groups = struct(Crowller.Data.ServerList).keygroups
    for index <- 0..length(key_groups)-1 do
      Task.start(fn() ->
        matched_group(Enum.at(key_groups, index))
      end)
    end
  end

end

And this is the error I get:

=INFO REPORT==== 15-Nov-2018::18:54:04.741174 ===
    application: crowller
    exited: {bad_return,
                {{'Elixir.Crowller.Application',start,[normal,[]]},
                 {'EXIT',
                     {undef,
                         [{'Elixir.Crowller.Application',start,[normal,[]],[]},
                          {application_master,start_it_old,4,
                              [{file,"application_master.erl"},
                               {line,277}]}]}}}}
    type: permanent
** (exit) exited in: GenServer.call(Mix.ProjectStack, {:get_and_update, #Function<14.775349/1 in Mix.ProjectStack.printable_app_name/0>}, 30000)
    ** (EXIT) no process: the process is not alive or there's no process currently associated with the given name, possibly because its application isn't started
    (elixir) lib/gen_server.ex:914: GenServer.call/3
    (mix) lib/mix/shell/io.ex:15: Mix.Shell.IO.print_app/0
    (mix) lib/mix/shell/io.ex:34: Mix.Shell.IO.error/1
    (mix) lib/mix/tasks/app.start.ex:135: Mix.Tasks.App.Start.ensure_all_started/2
    (elixir) lib/enum.ex:765: Enum."-each/2-lists^foreach/1-0-"/2
    (elixir) lib/enum.ex:765: Enum.each/2
    (mix) lib/mix/tasks/app.start.ex:114: Mix.Tasks.App.Start.start/2
    (mix) lib/mix/tasks/app.start.ex:86: Mix.Tasks.App.Start.run/1
*** Shell process terminated! (^G to start new job) ***
{"Kernel pid terminated",application_controller,"{application_start_failure,crowller,{bad_return,{{'Elixir.Crowller.Application',start,[normal,[]]},{'EXIT',{undef,[{'Elixir.Crowller.Application',start,[normal,[]],[]},{application_master,start_it_old,4,[{file,\"application_master.erl\"},{line,277}]}]}}}}}"}
Kernel pid terminated (application_controller) ({application_start_failure,crowller,{bad_return,{{'Elixir.Crowller.Application',start,[normal,[]]},{'EXIT',{undef,[{'Elixir.Crowller.
Application',start,

Upvotes: 1

Views: 4086

Answers (1)

Sheharyar
Sheharyar

Reputation: 75740

In your Mixfile, you specified that your project is an Erlang application with a supervision tree:

[mod: {Crowller.Application, []}]

That means your Crowller.Application module must implement a start/2 callback that boots up the application supervision tree. While you're already implementing the method, you're aren't actually starting any processes or supervising them according to the specification:

The start/2 callback has to spawn and link a supervisor and return {:ok, pid} or {:ok, pid, state}, where pid is the PID of the supervisor, and state is an optional application state. args is the second element of the tuple given to the :mod option.


You can do that by using the Supervisor helpers:

defmodule Crowller.Application do
  use Application

  def start(_type, _args) do
    children = []     # Add your subprocesses here (if any)
    Supervisor.start_link(children, strategy: :one_for_one)
  end
end

Upvotes: 3

Related Questions