Skip to content

Commit 22f0ef8

Browse files
committed
Handle stop-on-first-error
1 parent 94b2fab commit 22f0ef8

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

lib/gradient.ex

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,13 @@ defmodule Gradient do
4444

4545
defp maybe_gradualizer_check(forms, opts) do
4646
unless opts[:no_gradualizer_check] do
47-
:gradualizer.type_check_forms(forms, opts)
47+
try do
48+
:gradualizer.type_check_forms(forms, opts)
49+
catch
50+
err ->
51+
{:attribute, _, :file, {path, _}} = hd(forms)
52+
[{path, err}]
53+
end
4854
else
4955
[]
5056
end

lib/mix/tasks/gradient.ex

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,19 +72,22 @@ defmodule Mix.Tasks.Gradient do
7272

7373
IO.puts("Typechecking files...")
7474

75-
res =
76-
files
77-
|> Stream.map(fn {app_path, paths} ->
78-
Stream.map(paths, &Gradient.type_check_file(&1, [{:app_path, app_path} | options]))
79-
end)
80-
|> Stream.concat()
81-
|> Enum.to_list()
75+
files
76+
|> Stream.map(fn {app_path, paths} ->
77+
Stream.map(paths, &Gradient.type_check_file(&1, [{:app_path, app_path} | options]))
78+
end)
79+
|> Stream.concat()
80+
|> execute(options)
81+
82+
:ok
83+
end
84+
85+
defp execute(stream, opts) do
86+
res = if opts[:crash_on_error], do: stream, else: Enum.to_list(stream)
8287

8388
if Enum.all?(res, &(&1 == :ok)) do
8489
IO.puts("No problems found!")
8590
end
86-
87-
:ok
8891
end
8992

9093
defp maybe_compile_project(options) do
@@ -122,6 +125,10 @@ defmodule Mix.Tasks.Gradient do
122125

123126
defp prepare_option({:fmt_location, v}, opts), do: [{:fmt_location, String.to_atom(v)} | opts]
124127

128+
defp prepare_option({:no_fancy, _}, opts), do: [{:fancy, false} | opts]
129+
130+
defp prepare_option({:stop_on_first_error, _}, opts), do: [{:crash_on_error, true} | opts]
131+
125132
defp prepare_option({k, v}, opts), do: [{k, v} | opts]
126133

127134
defp get_beams_paths([]) do

0 commit comments

Comments
 (0)