Skip to content

Commit 8d933ce

Browse files
committed
Abort on errors
Fixes several instances where the task would try to complete after encountering an error. Improves output when errors do occur by printing an informative message under noral opperation, and only print the full stacktrace when DEBUG=1 is used. When displayed stacktraces are formatted better by starting them on a new line. Signed-off-by: Winford <[email protected]>
1 parent d667e48 commit 8d933ce

File tree

1 file changed

+20
-21
lines changed

1 file changed

+20
-21
lines changed

src/atomvm_dialyzer_provider.erl

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,8 @@ do(State) ->
7979
{ok, State}
8080
catch
8181
C:E:S ->
82-
rebar_api:error(
83-
"An error occurred in the ~p task. Class=~p Error=~p Stacktrace=~p~n", [
84-
?PROVIDER, C, E, S
85-
]
86-
),
82+
rebar_api:error("An error occurred in the ~p task.", [?PROVIDER]),
83+
rebar_api:debug("Class=~p Error=~p~nSTACKTRACE:~n~p~n", [C, E, S]),
8784
{error, E}
8885
end.
8986

@@ -147,7 +144,7 @@ do_dialize(Config, State) ->
147144
print_warnings(Problems)
148145
catch
149146
throw:{dialyzer_error, Reason} ->
150-
rebar_api:error("Dialyzer failed! reason: ~p.~n", [Reason])
147+
rebar_api:abort("Dialyzer failed! reason: ~p.~n", [Reason])
151148
end,
152149
ok.
153150

@@ -163,10 +160,10 @@ check_base_plt(Config) ->
163160
[] ->
164161
ok;
165162
_ ->
166-
do_build_base_plt(Config)
163+
ok = do_build_base_plt(Config)
167164
catch
168165
throw:{dialyzer_error, _} ->
169-
do_build_base_plt(Config)
166+
ok = do_build_base_plt(Config)
170167
end,
171168
ok.
172169

@@ -175,7 +172,7 @@ base_plt_absname(Config) ->
175172
Home =
176173
case os:getenv("HOME") of
177174
false ->
178-
rebar_api:error("Unable to locate users home directory");
175+
rebar_api:abort("Unable to locate users home directory", []);
179176
Path ->
180177
string:trim(Path)
181178
end,
@@ -200,12 +197,13 @@ do_build_base_plt(Config) ->
200197
ok;
201198
Failure ->
202199
print_warnings(Failure),
203-
rebar_api:error("Failed to create project plt!~n")
200+
rebar_api:abort("Failed to create project plt!~n", []),
201+
{error, dialyzer_error}
204202
catch
205203
throw:{dialyzer_error, Error} ->
206-
rebar_api:error("Failed to crete plt, error:~p~n", [Error])
207-
end,
208-
ok.
204+
rebar_api:abort("Failed to crete plt, error:~p~n", [Error]),
205+
{error, dialyzer_error}
206+
end.
209207

210208
% @private
211209
check_app_plt(Config, State) ->
@@ -216,7 +214,7 @@ check_app_plt(Config, State) ->
216214
ok
217215
catch
218216
throw:{dialyzer_error, _} ->
219-
do_build_plt(Config, State)
217+
ok = do_build_plt(Config, State)
220218
end,
221219
ok.
222220

@@ -240,12 +238,13 @@ do_build_plt(Config, State) ->
240238
ok;
241239
Failure ->
242240
print_warnings(Failure),
243-
rebar_api:error("Failed to create project plt!~n")
241+
rebar_api:abort("Failed to create project plt!~n", []),
242+
{error, dialyzer_error}
244243
catch
245244
throw:{dialyzer_error, Error} ->
246-
rebar_api:error("Failed to crete plt, error:~p~n", [Error])
247-
end,
248-
ok.
245+
rebar_api:abort("Failed to crete plt, error:~p~n", [Error]),
246+
{error, dialyzer_error}
247+
end.
249248

250249
%% @private
251250
plt_absolute_name(State) ->
@@ -278,7 +277,7 @@ atomvm_install_path() ->
278277
BinPath =
279278
case os:find_executable("atomvm") of
280279
false ->
281-
rebar_api:error("Path to AtomVM installation not found!");
280+
rebar_api:abort("Path to AtomVM installation not found!", []);
282281
AtomVM ->
283282
AtomVM
284283
end,
@@ -307,7 +306,7 @@ get_base_beam_path_list(Base) ->
307306
rebar_api:debug("AtomVM libraries to add to plt: ~p~n", [Libs]),
308307
case Libs of
309308
[] ->
310-
rebar_api:error("Unable to locate AtomVM beams in path"),
309+
rebar_api:abort("Unable to locate AtomVM beams in path", []),
311310
{error, no_beams_found};
312311
Ebins ->
313312
Ebins
@@ -332,7 +331,7 @@ app_profile_abs_dir(State) ->
332331
Prof1 when is_atom(Prof1) ->
333332
Prof1;
334333
Arg ->
335-
rebar_api:error("Unable to determine rebar3 profile, got badarg ~p", [Arg]),
334+
rebar_api:abort("Unable to determine rebar3 profile, got badarg ~p", [Arg]),
336335
{error, bad_rebar_profile}
337336
end,
338337
WorkDir = filename:absname(filename:join("_build", Profile)),

0 commit comments

Comments
 (0)