summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/rebar3.erl54
-rw-r--r--src/rebar_base_compiler.erl33
-rw-r--r--src/rebar_prv_xref.erl10
3 files changed, 49 insertions, 48 deletions
diff --git a/src/rebar3.erl b/src/rebar3.erl
index 92803c5..1a02407 100644
--- a/src/rebar3.erl
+++ b/src/rebar3.erl
@@ -44,33 +44,14 @@
%% escript Entry point
main(Args) ->
- case catch(run(Args)) of
+ try run(Args) of
{ok, _State} ->
erlang:halt(0);
- rebar_abort ->
- erlang:halt(1);
- {error, rebar_abort} ->
- erlang:halt(1);
- {error, {Module, Reason}} ->
- case code:which(Module) of
- non_existing ->
- ?ERROR("Uncaught error in rebar_core. Run with DEBUG=1 to see stacktrace", []),
- ?DEBUG("Uncaught error: ~p ~p", [Module, Reason]),
- ?INFO("When submitting a bug report, please include the output of `rebar3 report \"your command\"`", []);
- _ ->
- ?ERROR(Module:format_error(Reason), [])
- end,
- erlang:halt(1);
- {error, Error} when is_list(Error) ->
- ?ERROR(Error, []),
- erlang:halt(1);
Error ->
- %% Nothing should percolate up from rebar_core;
- %% Dump this error to console
- ?ERROR("Uncaught error in rebar_core. Run with DEBUG=1 to see stacktrace", []),
- ?DEBUG("Uncaught error: ~p", [Error]),
- ?INFO("When submitting a bug report, please include the output of `rebar3 report \"your command\"`", []),
- erlang:halt(1)
+ handle_error(Error)
+ catch
+ _:Error ->
+ handle_error(Error)
end.
%% Erlang-API entry point
@@ -251,3 +232,28 @@ global_option_spec_list() ->
%{config, $C, "config", string, "Rebar config file to use."},
{task, undefined, undefined, string, "Task to run."}
].
+
+handle_error(rebar_abort) ->
+ erlang:halt(1);
+handle_error({error, rebar_abort}) ->
+ erlang:halt(1);
+handle_error({error, {Module, Reason}}) ->
+ case code:which(Module) of
+ non_existing ->
+ ?ERROR("Uncaught error in rebar_core. Run with DEBUG=1 to see stacktrace", []),
+ ?DEBUG("Uncaught error: ~p ~p", [Module, Reason]),
+ ?INFO("When submitting a bug report, please include the output of `rebar3 report \"your command\"`", []);
+ _ ->
+ ?ERROR(Module:format_error(Reason), [])
+ end,
+ erlang:halt(1);
+handle_error({error, Error}) when is_list(Error) ->
+ ?ERROR(Error, []),
+ erlang:halt(1);
+handle_error(Error) ->
+ %% Nothing should percolate up from rebar_core;
+ %% Dump this error to console
+ ?ERROR("Uncaught error in rebar_core. Run with DEBUG=1 to see stacktrace", []),
+ ?DEBUG("Uncaught error: ~p", [Error]),
+ ?INFO("When submitting a bug report, please include the output of `rebar3 report \"your command\"`", []),
+ erlang:halt(1).
diff --git a/src/rebar_base_compiler.erl b/src/rebar_base_compiler.erl
index 0101218..7193003 100644
--- a/src/rebar_base_compiler.erl
+++ b/src/rebar_base_compiler.erl
@@ -69,12 +69,12 @@ run(Config, FirstFiles, SourceDir, SourceExt, TargetDir, TargetExt,
simple_compile_wrapper(S, Target, Compile3Fn, C, CheckLastMod)
end).
-ok_tuple(Config, Source, Ws) ->
- {ok, format_warnings(Config, Source, Ws)}.
+ok_tuple(_Config, Source, Ws) ->
+ {ok, format_warnings(Source, Ws)}.
-error_tuple(Config, Source, Es, Ws, Opts) ->
- {error, format_errors(Config, Source, Es),
- format_warnings(Config, Source, Ws, Opts)}.
+error_tuple(_Config, Source, Es, Ws, Opts) ->
+ {error, format_errors(Source, Es),
+ format_warnings(Source, Ws, Opts)}.
%% ===================================================================
%% Internal functions
@@ -114,26 +114,25 @@ compile_each([Source | Rest], Config, CompileFn) ->
skipped ->
?DEBUG("~sSkipped ~s", [rebar_utils:indent(1), filename:basename(Source)]);
Error ->
- ?ERROR("Compiling ~s failed",
- [maybe_absname(Config, Source)]),
+ ?ERROR("Compiling ~s failed", [Source]),
maybe_report(Error),
?DEBUG("Compilation failed: ~p", [Error]),
?FAIL
end,
compile_each(Rest, Config, CompileFn).
-format_errors(Config, Source, Errors) ->
- format_errors(Config, Source, "", Errors).
+format_errors(Source, Errors) ->
+ format_errors(Source, "", Errors).
-format_warnings(Config, Source, Warnings) ->
- format_warnings(Config, Source, Warnings, []).
+format_warnings(Source, Warnings) ->
+ format_warnings(Source, Warnings, []).
-format_warnings(Config, Source, Warnings, Opts) ->
+format_warnings(Source, Warnings, Opts) ->
Prefix = case lists:member(warnings_as_errors, Opts) of
true -> "";
false -> "Warning: "
end,
- format_errors(Config, Source, Prefix, Warnings).
+ format_errors(Source, Prefix, Warnings).
maybe_report({{error, {error, _Es, _Ws}=ErrorsAndWarnings}, {source, _}}) ->
maybe_report(ErrorsAndWarnings);
@@ -148,10 +147,9 @@ maybe_report(_) ->
report(Messages) ->
lists:foreach(fun(Msg) -> io:format("~s~n", [Msg]) end, Messages).
-format_errors(Config, _MainSource, Extra, Errors) ->
+format_errors(_MainSource, Extra, Errors) ->
[begin
- AbsSource = maybe_absname(Config, Source),
- [format_error(AbsSource, Extra, Desc) || Desc <- Descs]
+ [format_error(Source, Extra, Desc) || Desc <- Descs]
end
|| {Source, Descs} <- Errors].
@@ -164,6 +162,3 @@ format_error(AbsSource, Extra, {Line, Mod, Desc}) ->
format_error(AbsSource, Extra, {Mod, Desc}) ->
ErrorDesc = Mod:format_error(Desc),
?FMT("~s: ~s~s~n", [AbsSource, Extra, ErrorDesc]).
-
-maybe_absname(_Config, Filename) ->
- Filename.
diff --git a/src/rebar_prv_xref.erl b/src/rebar_prv_xref.erl
index 1d1afa0..ed53da6 100644
--- a/src/rebar_prv_xref.erl
+++ b/src/rebar_prv_xref.erl
@@ -248,11 +248,11 @@ format_mfa_source(MFA) ->
%% Extract an element from a tuple, or undefined if N > tuple size
%%
safe_element(N, Tuple) ->
- case catch(element(N, Tuple)) of
- {'EXIT', {badarg, _}} ->
- undefined;
- Value ->
- Value
+ try
+ element(N, Tuple)
+ catch
+ error:badarg ->
+ undefined
end.
%%