diff options
| author | Tristan Sloughter <t@crashfast.com> | 2015-05-10 18:55:50 -0500 | 
|---|---|---|
| committer | Tristan Sloughter <t@crashfast.com> | 2015-05-10 19:24:19 -0500 | 
| commit | fa95321774f930c1d1e294403ee1cdac2d5be428 (patch) | |
| tree | fbb4958ef930a3e5f6e65e0f725453012c0e4516 /src | |
| parent | 062bee5985463ef3dcd35af3b0a34b946fd710f5 (diff) | |
remove uses of 'case catch'
Diffstat (limited to 'src')
| -rw-r--r-- | src/rebar3.erl | 54 | ||||
| -rw-r--r-- | src/rebar_base_compiler.erl | 33 | ||||
| -rw-r--r-- | src/rebar_prv_xref.erl | 10 | 
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.  %% | 
