Skip to content

Commit 691c1d4

Browse files
committed
fix: properly render the child that must be placed in the supervision tree
fixes #306
1 parent fad2946 commit 691c1d4

2 files changed

Lines changed: 45 additions & 2 deletions

File tree

lib/igniter/project/application.ex

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,10 +334,16 @@ defmodule Igniter.Project.Application do
334334
end
335335
else
336336
_ ->
337+
to_supervise =
338+
case to_supervise do
339+
module when is_atom(module) -> inspect(module)
340+
{module, opts} -> "{#{inspect(module)}, #{Macro.to_string(opts)}}"
341+
end
342+
337343
{:warning,
338344
"""
339-
Could not find a `children = [...]` assignment in the `start` function of the `#{application}` module.
340-
Please ensure that #{inspect(to_supervise)} is added started by the application `#{application}` manually.
345+
Could not find a `children = [...]` assignment in the `start` function of the `#{inspect(application)}` module.
346+
Please ensure that #{to_supervise} is added started by the application `#{inspect(application)}` manually.
341347
"""}
342348
end
343349
end)

test/igniter/project/application_test.exs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,43 @@ defmodule Igniter.Project.ApplicationTest do
7777
""")
7878
end
7979

80+
test "gives a nice warning when children can't be found" do
81+
test_project(
82+
files: %{
83+
"lib/test/application.ex" => """
84+
defmodule Test.Application do
85+
@moduledoc false
86+
87+
use Application
88+
89+
@impl true
90+
def start(_type, _args) do
91+
something = []
92+
93+
opts = [strategy: :one_for_one, name: Test.Supervisor]
94+
Supervisor.start_link(something, opts)
95+
end
96+
end
97+
"""
98+
}
99+
)
100+
|> Igniter.Project.MixProject.update(:application, [:mod], fn _zipper ->
101+
{:ok, {:code, "{Test.Application, []}"}}
102+
end)
103+
|> apply_igniter!()
104+
|> Igniter.Project.Application.add_new_child({Foo, a: :b})
105+
|> assert_has_warning(fn warning ->
106+
String.contains?(
107+
warning,
108+
"Please ensure that {Foo, [a: :b]} is added started by the application `Test.Application` manually."
109+
) and
110+
String.contains?(
111+
warning,
112+
"Could not find a `children = [...]`"
113+
)
114+
end)
115+
end
116+
80117
test "supports updating options using `opts_updater`" do
81118
test_project()
82119
|> Igniter.Project.Application.add_new_child({Foo, a: :b})

0 commit comments

Comments
 (0)