Elixir 中的错误:返回了错误的值::ok
Error in Elixir : returned a bad value: :ok
我在使用 Elixir 时遇到了一些问题。
这是我的 mix.exs
...
defmodule FlockTest.Mixfile do
use Mix.Project
def project do
[app: :flock_test,
version: "0.1.0",
elixir: "~> 1.4",
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
# Specify extra applications you'll use from Erlang/Elixir
[
extra_applications: [:logger],
mod: {FlockTest, []}
]
end
...
...
这是 FlockTest
的代码。
defmodule FlockTest do
@moduledoc """
Documentation for FlockTest.
"""
def start(_type, _args) do
IO.puts "Start Flock"
end
end
我 运行 此代码 mix run --no-halt
但这导致了这样的错误。
=INFO REPORT==== 12-Nov-2017::17:47:39 ===
application: logger
exited: stopped
type: temporary
** (Mix) Could not start application flock_test: FlockTest.start(:normal,
[]) returned a bad value: :ok
我是不是做错了什么?
您的应用程序的 start/2
函数应该启动并且 return 应用程序的顶级进程,通常是主管实例。现在你 return return 由 IO.puts
编辑的值,即 :ok
成功。有效 return 值是 {:ok, pid} | {:ok, pid, state} | {:error, reason :: term}
,如记录 here。例如,您可以使用 mix new foo --sup
创建一个新应用程序并查看 lib/foo/application.ex
。这是它的 start/2
的样子:
def start(_type, _args) do
# List all child processes to be supervised
children = [
# Starts a worker by calling: A.Worker.start_link(arg)
# {A.Worker, arg},
]
# See https://hexdocs.pm/elixir/Supervisor.html
# for other strategies and supported options
opts = [strategy: :one_for_one, name: A.Supervisor]
Supervisor.start_link(children, opts)
end
我在使用 Elixir 时遇到了一些问题。
这是我的 mix.exs
...
defmodule FlockTest.Mixfile do
use Mix.Project
def project do
[app: :flock_test,
version: "0.1.0",
elixir: "~> 1.4",
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
# Specify extra applications you'll use from Erlang/Elixir
[
extra_applications: [:logger],
mod: {FlockTest, []}
]
end
...
...
这是 FlockTest
的代码。
defmodule FlockTest do
@moduledoc """
Documentation for FlockTest.
"""
def start(_type, _args) do
IO.puts "Start Flock"
end
end
我 运行 此代码 mix run --no-halt
但这导致了这样的错误。
=INFO REPORT==== 12-Nov-2017::17:47:39 ===
application: logger
exited: stopped
type: temporary
** (Mix) Could not start application flock_test: FlockTest.start(:normal,
[]) returned a bad value: :ok
我是不是做错了什么?
您的应用程序的 start/2
函数应该启动并且 return 应用程序的顶级进程,通常是主管实例。现在你 return return 由 IO.puts
编辑的值,即 :ok
成功。有效 return 值是 {:ok, pid} | {:ok, pid, state} | {:error, reason :: term}
,如记录 here。例如,您可以使用 mix new foo --sup
创建一个新应用程序并查看 lib/foo/application.ex
。这是它的 start/2
的样子:
def start(_type, _args) do
# List all child processes to be supervised
children = [
# Starts a worker by calling: A.Worker.start_link(arg)
# {A.Worker, arg},
]
# See https://hexdocs.pm/elixir/Supervisor.html
# for other strategies and supported options
opts = [strategy: :one_for_one, name: A.Supervisor]
Supervisor.start_link(children, opts)
end