Elixir 1.5 / OTP 20
defmodule Test.Sup do
use Supervisor
def start_link(opts), do: Supervisor.start_link(__MODULE__, opts, name: __MODULE__)
def init([]) do
children = [
Test.Server
]
# Does not work: supervise(children, strategy: :one_for_one)
Supervisor.init(children, strategy: :one_for_one)
end
end
defmodule Test.Server do
use GenServer
def start_link(opts), do: GenServer.start_link(__MODULE__, opts, name: __MODULE__)
def init([]) do
{:ok, :no_state}
end
end
From the docs for Supervisor.Spec.supervise:
This tuple can be used as the return value of the c:init/1 callback when implementing a module-based supervisor.
Instead, supervise fails with:
** (Mix) Could not start application foo: Foo.Application.start(:normal, []) returned an error: shutdown: failed to start child: Test.Sup
** (EXIT) an exception was raised:
** (ArgumentError) argument error
(elixir) lib/supervisor/spec.ex:175: anonymous fn/1 in Supervisor.Spec.supervise/2
Either Supervisor.Spec.supervise should be updated to work with the new child_spec functionality, or the function docs should be updated to note that it's not compatible.
Thanks for the quick response! Would you consider throwing an actual deprecation warning when any child passed to supervise is a bare module/tuple?
Also, your commit adds a comment at the module level. Perhaps the function docs could be updated as well? For example:
This tuple can be used as the return value of the c:init/1 callback when implementing a module-based supervisor. This is not compatible with Elixir 1.5's changes to
child_spec.
Alternately, could this be caught by a type check?
@pikeas i would like to wait if others will run into this same issue. If they do, we can see ways to make it clearer that old API does not support the new features. Especially since v1.5.1 already has some improvements on this area compared to v1.5.0.
I have run into this same error just now.
I'm trying to update Phoenix 1.3's generated application.ex to remove some of the dependency on Supervisor.Spec import. Replacing a worker(MyModule, []) call with {MyModule, []} or MyModule generates the above error.
I'm somewhat confused -- is the right course of action to continue to use Supervisor.Spec.worker() for now?
I'm somewhat confused -- is the right course of action to continue to use Supervisor.Spec.worker() for now?
@michaelgundlach yes, it is until v1.5.1 is out - which has some fixes that will make integrating both easier.
I have reopened this so we improve the error message in the upcoming v1.5.1. It should be out tomorrow or wednesday.
The 1.5 release notes read as "use the new child_spec for children", but your comment here reads as "do not use the new child_spec, continue using worker() and supervisor()".
Could you provide a bit more guidance? It's unclear whether we should be using the new functionality at all.
I understand completely now. The issue is that the old syntax does not allow the new syntax and the new syntax does not allow the old one. However, this has been fixed in master and v1.5 already so the new syntax allows both formats and the old one just the old one. So we just need to improve the warnings for the old one.
You should use the new API but that requires using the new format. Elixir v1.5.1 will make sure that the new API also works with the old constructs, so it should have all bases covered.
Thanks. I'd love to use the new API but mix phx.new appeared to generate
code using the old constructs. Looking forward to 1.5.1 :)
On Mon, Jul 31, 2017 at 3:51 PM, José Valim notifications@github.com
wrote:
I understand completely now. The issue is that the old syntax does not
allow the new syntax and the new syntax does not allow the old one.
However, this has been fixed in master and v1.5 already so the new syntax
allows both formats and the old one just the old one. So we just need to
improve the warnings for the old one.You should use the new API but that requires using the new format. Elixir
v1.5.1 will make sure that the new API also works with the old constructs,
so it should have all bases covered.—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/elixir-lang/elixir/issues/6407#issuecomment-319177023,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AE5zVX9g-eSsNMT8n3sJVR9p8RJwYS1Kks5sTjBbgaJpZM4OnyaE
.
v1.5.1 is out!
I'm getting this. The problem is I don't know where to go from here. Using Elixir 1.7.4 and plug_cowboy 2.0.2.
What do I do instead of calling child_spec? The plug guide says to use the child_spec function. https://hexdocs.pm/plug/readme.html#supervised-handlers
@mortalisk can you please provide the full error you are getting? Also please paste your code and as much information as you can.
Most helpful comment
v1.5.1 is out!