Skip to content

Commit 8361958

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 <winford@object.stream>
1 parent a3faf1d commit 8361958

File tree

1 file changed

+16
-23
lines changed

1 file changed

+16
-23
lines changed

src/atomvm_dialyzer_provider.erl

Lines changed: 16 additions & 23 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 (~p) occurred in the ~p task.", [E, ?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,11 @@ 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", [])
204201
catch
205202
throw:{dialyzer_error, Error} ->
206-
rebar_api:error("Failed to crete plt, error:~p~n", [Error])
207-
end,
208-
ok.
203+
rebar_api:abort("Failed to crete plt, error:~p~n", [Error])
204+
end.
209205

210206
% @private
211207
check_app_plt(Config, State) ->
@@ -216,7 +212,7 @@ check_app_plt(Config, State) ->
216212
ok
217213
catch
218214
throw:{dialyzer_error, _} ->
219-
do_build_plt(Config, State)
215+
ok = do_build_plt(Config, State)
220216
end,
221217
ok.
222218

@@ -240,12 +236,11 @@ do_build_plt(Config, State) ->
240236
ok;
241237
Failure ->
242238
print_warnings(Failure),
243-
rebar_api:error("Failed to create project plt!~n")
239+
rebar_api:abort("Failed to create project plt!~n", [])
244240
catch
245241
throw:{dialyzer_error, Error} ->
246-
rebar_api:error("Failed to crete plt, error:~p~n", [Error])
247-
end,
248-
ok.
242+
rebar_api:abort("Failed to crete plt, error: ~p~n", [Error])
243+
end.
249244

250245
%% @private
251246
plt_absolute_name(State) ->
@@ -278,7 +273,7 @@ atomvm_install_path() ->
278273
BinPath =
279274
case os:find_executable("atomvm") of
280275
false ->
281-
rebar_api:error("Path to AtomVM installation not found!");
276+
rebar_api:abort("Path to AtomVM installation not found!", []);
282277
AtomVM ->
283278
AtomVM
284279
end,
@@ -321,8 +316,7 @@ get_base_beam_path_list(Base) ->
321316
rebar_api:debug("AtomVM libraries to add to plt: ~p~n", [Libs]),
322317
case Libs of
323318
[] ->
324-
rebar_api:error("Unable to locate AtomVM beams in path"),
325-
{error, no_beams_found};
319+
rebar_api:abort("Unable to locate AtomVM beams in path", []);
326320
Ebins ->
327321
Ebins
328322
end.
@@ -348,8 +342,7 @@ app_profile_abs_dir(State) ->
348342
Prof1 when is_atom(Prof1) ->
349343
Prof1;
350344
Arg ->
351-
rebar_api:error("Unable to determine rebar3 profile, got badarg ~p", [Arg]),
352-
{error, bad_rebar_profile}
345+
rebar_api:abort("Unable to determine rebar3 profile, got badarg ~p", [Arg])
353346
end,
354347
WorkDir = filename:absname(filename:join("_build", Profile)),
355348
ok = filelib:ensure_path(WorkDir),

0 commit comments

Comments
 (0)