Skip to content

Commit 78c00b1

Browse files
committed
fix: don't silently ignore certain errors during spinners
fix: don't display "temporarily adding igniter" when we aren't closes #331 closes #333
1 parent 7508897 commit 78c00b1

File tree

6 files changed

+53
-49
lines changed

6 files changed

+53
-49
lines changed

installer/lib/loading.ex

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,8 @@ defmodule Igniter.Installer.Loading do
6868
|> elem(0)
6969
end)
7070
|> elem(0)
71-
rescue
72-
e ->
73-
Process.put(:spinner_error, true)
74-
Mix.shell(shell)
75-
Mix.shell().info(Igniter.Installer.CaptureServer.device_output(:standard_error, ref))
76-
reraise e, __STACKTRACE__
7771
catch
7872
kind, reason ->
79-
File.write("catch_output", inspect({kind, reason}))
8073
Process.put(:spinner_error, true)
8174
Mix.shell(shell)
8275
Mix.shell().info(Igniter.Installer.CaptureServer.device_output(:standard_error, ref))

installer/lib/task_helpers.ex

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -191,21 +191,21 @@ defmodule Igniter.Installer.TaskHelpers do
191191
|> File.read!()
192192

193193
new_contents =
194+
new_contents =
195+
contents
196+
|> add_igniter_dep()
197+
198+
if contents == new_contents do
199+
contents
200+
else
194201
Igniter.Installer.Loading.with_spinner(
195202
"temporarily adding igniter",
196203
fn ->
197-
new_contents =
198-
contents
199-
|> add_igniter_dep()
200-
201-
if contents == new_contents do
202-
contents
203-
else
204-
new_contents
205-
|> Code.format_string!()
206-
end
204+
new_contents
205+
|> Code.format_string!()
207206
end
208207
)
208+
end
209209

210210
if new_contents == contents && !String.contains?(contents, "{:igniter,") do
211211
Mix.shell().error("""

lib/igniter/extensions/phoenix.ex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ defmodule Igniter.Extensions.Phoenix do
2121

2222
cond do
2323
# Check if this is a LiveView/LiveComponent module but NOT if "Live" is just a namespace
24-
String.ends_with?(Enum.at(split, 1) || "", "Live") &&
25-
# Exclude the case where element 1 is exactly "Live" (namespace usage)
26-
Enum.at(split, 1) != "Live" ->
24+
# Exclude the case where element 1 is exactly "Live" (namespace usage)
25+
String.ends_with?(Enum.at(split, 1) || "", "Live") &&
26+
Enum.at(split, 1) != "Live" ->
2727
[base | rest] = split
2828

2929
{:ok,

lib/igniter/util/install.ex

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,9 @@ defmodule Igniter.Util.Install do
209209
end
210210

211211
def get_deps!(igniter, opts) do
212-
case System.cmd("mix", ["deps.get"], stderr_to_stdout: true) do
212+
case Igniter.Util.Loading.with_spinner("fetching deps", fn ->
213+
raising_cmd!("mix", ["deps.get"], stderr_to_stdout: true)
214+
end) do
213215
{_output, 0} ->
214216
Igniter.Util.Loading.with_spinner(
215217
opts[:operation] || "building deps",
@@ -220,14 +222,14 @@ defmodule Igniter.Util.Install do
220222
igniter
221223

222224
[:all] ->
223-
System.cmd("mix", ["deps.update", "--all" | opts[:update_deps_args] || []],
225+
raising_cmd!("mix", ["deps.update", "--all" | opts[:update_deps_args] || []],
224226
stderr_to_stdout: true
225227
)
226228

227229
%{igniter | rewrite: Rewrite.drop(igniter.rewrite, ["mix.lock"])}
228230

229231
to_update ->
230-
System.cmd(
232+
raising_cmd!(
231233
"mix",
232234
["deps.update" | to_update] ++ (opts[:update_deps_args] || []),
233235
stderr_to_stdout: true
@@ -251,8 +253,8 @@ defmodule Igniter.Util.Install do
251253

252254
igniter =
253255
if Keyword.get(opts, :compile_deps?, true) do
254-
System.cmd("mix", ["deps.get"], stderr_to_stdout: true)
255-
System.cmd("mix", ["deps.compile"], stderr_to_stdout: true)
256+
raising_cmd!("mix", ["deps.get"], stderr_to_stdout: true)
257+
raising_cmd!("mix", ["deps.compile"], stderr_to_stdout: true)
256258

257259
%{igniter | rewrite: Rewrite.drop(igniter.rewrite, ["mix.lock"])}
258260
else
@@ -292,6 +294,22 @@ defmodule Igniter.Util.Install do
292294
end
293295
end
294296

297+
defp raising_cmd!(cmd, args, opts) do
298+
case System.cmd(cmd, args, opts) do
299+
{output, 0} ->
300+
{output, 0}
301+
302+
{output, n} ->
303+
raise """
304+
#{cmd} #{Enum.join(args, " ")} exited with status: #{n}
305+
306+
Output:
307+
308+
#{output}
309+
"""
310+
end
311+
end
312+
295313
defp handle_error(output, _exit_code, igniter, opts) do
296314
if String.contains?(output, "Dependencies have diverged") do
297315
handle_diverged_dependencies(output, igniter, opts)

lib/igniter/util/loading.ex

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,8 @@ defmodule Igniter.Util.Loading do
6666
|> elem(0)
6767
end)
6868
|> elem(0)
69-
rescue
70-
e ->
71-
Process.put(:spinner_error, true)
72-
Mix.shell(shell)
73-
Mix.shell().info(Igniter.CaptureServer.device_output(:standard_error, ref))
74-
reraise e, __STACKTRACE__
7569
catch
7670
kind, reason ->
77-
File.write("catch_output", inspect({kind, reason}))
7871
Process.put(:spinner_error, true)
7972
Mix.shell(shell)
8073
Mix.shell().info(Igniter.CaptureServer.device_output(:standard_error, ref))

test/igniter/extensions/phoenix_test.exs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -84,47 +84,47 @@ defmodule Igniter.Extensions.PhoenixTest do
8484
igniter =
8585
test_project()
8686
|> Igniter.Project.IgniterConfig.add_extension(Igniter.Extensions.Phoenix)
87-
87+
8888
module_name = MyApp.Live.Dashboard.TestLive
89-
90-
igniter =
89+
90+
igniter =
9191
Igniter.Project.Module.create_module(igniter, module_name, """
9292
@moduledoc "Test module"
9393
def hello, do: :world
9494
""")
95-
96-
{:ok, {_igniter, source, _zipper}} =
95+
96+
{:ok, {_igniter, source, _zipper}} =
9797
Igniter.Project.Module.find_module(igniter, module_name)
98-
98+
9999
actual_path = Rewrite.Source.get(source, :path)
100-
100+
101101
refute actual_path =~ ~r/live\/live/,
102-
"Module path should not contain duplicate 'live/live' directories. Got: #{actual_path}"
103-
102+
"Module path should not contain duplicate 'live/live' directories. Got: #{actual_path}"
103+
104104
assert actual_path == "lib/my_app/live/dashboard/test_live.ex"
105105
end
106106

107107
test "correctly handles LiveView modules with Web prefix" do
108108
igniter =
109109
test_project()
110110
|> Igniter.Project.IgniterConfig.add_extension(Igniter.Extensions.Phoenix)
111-
111+
112112
module_name = TestWeb.DashboardLive
113-
114-
igniter =
113+
114+
igniter =
115115
Igniter.Project.Module.create_module(igniter, module_name, """
116116
use TestWeb, :live_view
117-
117+
118118
def render(assigns) do
119119
~H"<div>Test</div>"
120120
end
121121
""")
122-
123-
{:ok, {_igniter, source, _zipper}} =
122+
123+
{:ok, {_igniter, source, _zipper}} =
124124
Igniter.Project.Module.find_module(igniter, module_name)
125-
125+
126126
actual_path = Rewrite.Source.get(source, :path)
127-
127+
128128
assert actual_path == "lib/test_web/live/dashboard_live.ex"
129129
end
130130
end

0 commit comments

Comments
 (0)