Skip to content

Commit 42f8a06

Browse files
author
José Valim
committed
Improve error message on invalid use of Supervisor.Spec
Closes #6407
1 parent e060a45 commit 42f8a06

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

lib/elixir/lib/supervisor/spec.ex

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,21 @@ defmodule Supervisor.Spec do
173173
maxR = Keyword.get(options, :max_restarts, 3)
174174
maxS = Keyword.get(options, :max_seconds, 5)
175175

176-
assert_unique_ids(Enum.map(children, &elem(&1, 0)))
176+
assert_unique_ids(Enum.map(children, &get_id/1))
177177
{:ok, {{strategy, maxR, maxS}, children}}
178178
end
179179

180+
defp get_id({id, _, _, _, _, _}) do
181+
id
182+
end
183+
defp get_id(other) do
184+
raise ArgumentError,
185+
"invalid tuple specification given to supervise/2. If you are trying to use " <>
186+
"the map child specification that is part of the Elixir v1.5, use Supervisor.init/2 " <>
187+
"instead of Supervisor.Spec.supervise/2. See the Supervisor module for more information. " <>
188+
"Got: #{inspect other}"
189+
end
190+
180191
defp assert_unique_ids([id | rest]) do
181192
if id in rest do
182193
raise ArgumentError,

0 commit comments

Comments
 (0)