diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/rebar.hrl | 6 | ||||
| -rw-r--r-- | src/rebar3.erl | 21 | ||||
| -rw-r--r-- | src/rebar_agent.erl | 4 | ||||
| -rw-r--r-- | src/rebar_core.erl | 3 | ||||
| -rw-r--r-- | src/rebar_dialyzer_format.erl | 4 | ||||
| -rw-r--r-- | src/rebar_fetch.erl | 4 | ||||
| -rw-r--r-- | src/rebar_plugins.erl | 4 | ||||
| -rw-r--r-- | src/rebar_prv_shell.erl | 33 | ||||
| -rw-r--r-- | src/rebar_prv_update.erl | 4 | ||||
| -rw-r--r-- | src/rebar_state.erl | 6 | ||||
| -rw-r--r-- | src/rebar_utils.erl | 11 | 
11 files changed, 55 insertions, 45 deletions
| diff --git a/src/rebar.hrl b/src/rebar.hrl index ca44283..f461c70 100644 --- a/src/rebar.hrl +++ b/src/rebar.hrl @@ -52,6 +52,12 @@  -type rebar_set() :: set().  -endif. +-ifdef(fun_stacktrace). +-define(WITH_STACKTRACE(T, R, S), T:R -> S = erlang:get_stacktrace(),). +-else. +-define(WITH_STACKTRACE(T, R, S), T:R:S ->). +-endif. +  -define(GRAPH_VSN, 2).  -type v() :: {digraph:vertex(), term()} | 'false'.  -type e() :: {digraph:vertex(), digraph:vertex()}. diff --git a/src/rebar3.erl b/src/rebar3.erl index eb5ad58..8e9d4b1 100644 --- a/src/rebar3.erl +++ b/src/rebar3.erl @@ -67,10 +67,10 @@ main(Args) ->          {ok, _State} ->              erlang:halt(0);          Error -> -            handle_error(Error) +            handle_error(Error, [])      catch -        _:Error -> -            handle_error(Error) +        ?WITH_STACKTRACE(_,Error,Stacktrace) +            handle_error(Error, Stacktrace)      end.  %% @doc Erlang-API entry point @@ -299,15 +299,15 @@ global_option_spec_list() ->  %% @private translate unhandled errors and internal return codes into proper  %% erroneous program exits. --spec handle_error(term()) -> no_return(). -handle_error(rebar_abort) -> +-spec handle_error(term(), term()) -> no_return(). +handle_error(rebar_abort, _) ->      erlang:halt(1); -handle_error({error, rebar_abort}) -> +handle_error({error, rebar_abort}, _) ->      erlang:halt(1); -handle_error({error, {Module, Reason}}) -> +handle_error({error, {Module, Reason}}, Stacktrace) ->      case code:which(Module) of          non_existing -> -            ?CRASHDUMP("~p: ~p~n~p~n~n", [Module, Reason, erlang:get_stacktrace()]), +            ?CRASHDUMP("~p: ~p~n~p~n~n", [Module, Reason, Stacktrace]),              ?ERROR("Uncaught error in rebar_core. Run with DEBUG=1 to stacktrace or consult rebar3.crashdump", []),              ?DEBUG("Uncaught error: ~p ~p", [Module, Reason]),              ?INFO("When submitting a bug report, please include the output of `rebar3 report \"your command\"`", []); @@ -315,13 +315,12 @@ handle_error({error, {Module, Reason}}) ->              ?ERROR("~ts", [Module:format_error(Reason)])      end,      erlang:halt(1); -handle_error({error, Error}) when is_list(Error) -> +handle_error({error, Error}, _) when is_list(Error) ->      ?ERROR("~ts", [Error]),      erlang:halt(1); -handle_error(Error) -> +handle_error(Error, StackTrace) ->      %% Nothing should percolate up from rebar_core;      %% Dump this error to console -    StackTrace = erlang:get_stacktrace(),      ?CRASHDUMP("Error: ~p~n~p~n~n", [Error, StackTrace]),      ?ERROR("Uncaught error in rebar_core. Run with DEBUG=1 to see stacktrace or consult rebar3.crashdump", []),      ?DEBUG("Uncaught error: ~p", [Error]), diff --git a/src/rebar_agent.erl b/src/rebar_agent.erl index b5dcfcf..8d0f9cf 100644 --- a/src/rebar_agent.erl +++ b/src/rebar_agent.erl @@ -114,8 +114,8 @@ run(Namespace, Command, StrArgs, RState, Cwd) ->                  {{error, cwd_changed}, RState}          end      catch -        Type:Reason -> -            ?DEBUG("Agent Stacktrace: ~p", [erlang:get_stacktrace()]), +        ?WITH_STACKTRACE(Type, Reason, Stacktrace) +            ?DEBUG("Agent Stacktrace: ~p", [Stacktrace]),              {{error, {Type, Reason}}, RState}      end. diff --git a/src/rebar_core.erl b/src/rebar_core.erl index 6132a5e..6a1cdbf 100644 --- a/src/rebar_core.erl +++ b/src/rebar_core.erl @@ -157,8 +157,7 @@ do([ProviderName | Rest], State) ->          {error, Error} ->              {error, Error}      catch -        error:undef -> -            Stack = erlang:get_stacktrace(), +        ?WITH_STACKTRACE(error,undef,Stack)              case Stack of                  [{ProviderName, do, [_], _}|_] ->                      %% This should really only happen if a plugin provider doesn't export do/1 diff --git a/src/rebar_dialyzer_format.erl b/src/rebar_dialyzer_format.erl index 5583633..cb0e958 100644 --- a/src/rebar_dialyzer_format.erl +++ b/src/rebar_dialyzer_format.erl @@ -53,9 +53,9 @@ format_warning_(Opts, Warning = {_Tag, {SrcFile, Line}, Msg}, {_LastFile, Acc})          String = message_to_string(Msg),          {SrcFile, [lists:flatten(fmt("~n~ts~n~!c~4w~!!: ~ts", [F, Line, String])) | Acc]}      catch -        Error:Reason -> +        ?WITH_STACKTRACE(Error, Reason, Stacktrace)              ?DEBUG("Failed to pretty format warning: ~p:~p~n~p", -                   [Error, Reason, erlang:get_stacktrace()]), +                   [Error, Reason, Stacktrace]),              {SrcFile, [dialyzer:format_warning(Warning, fullpath) | Acc]}      end. diff --git a/src/rebar_fetch.erl b/src/rebar_fetch.erl index f68a54d..d2c7706 100644 --- a/src/rebar_fetch.erl +++ b/src/rebar_fetch.erl @@ -32,8 +32,8 @@ download_source(AppDir, Source, State) ->          Error ->              throw(?PRV_ERROR(Error))      catch -        C:T -> -            ?DEBUG("rebar_fetch exception ~p ~p ~p", [C, T, erlang:get_stacktrace()]), +        ?WITH_STACKTRACE(C,T,S) +            ?DEBUG("rebar_fetch exception ~p ~p ~p", [C, T, S]),              throw(?PRV_ERROR({fetch_fail, Source}))      end. diff --git a/src/rebar_plugins.erl b/src/rebar_plugins.erl index 57c34bc..bc6a1e0 100644 --- a/src/rebar_plugins.erl +++ b/src/rebar_plugins.erl @@ -114,8 +114,8 @@ handle_plugin(Profile, Plugin, State, Upgrade) ->          {plugin_providers(Plugin), State4}      catch -        C:T -> -            ?DEBUG("~p ~p ~p", [C, T, erlang:get_stacktrace()]), +        ?WITH_STACKTRACE(C,T,S) +            ?DEBUG("~p ~p ~p", [C, T, S]),              ?WARN("Plugin ~p not available. It will not be used.", [Plugin]),              {[], State}      end. diff --git a/src/rebar_prv_shell.erl b/src/rebar_prv_shell.erl index 2c48083..9a320ad 100644 --- a/src/rebar_prv_shell.erl +++ b/src/rebar_prv_shell.erl @@ -201,21 +201,28 @@ rewrite_leaders(OldUser, NewUser) ->              lists:member(proplists:get_value(group_leader, erlang:process_info(Pid)),                           OldMasters)],      try -        %% enable error_logger's tty output -        error_logger:swap_handler(tty), -        %% disable the simple error_logger (which may have been added multiple -        %% times). removes at most the error_logger added by init and the -        %% error_logger added by the tty handler -        remove_error_handler(3), -        %% reset the tty handler once more for remote shells -        error_logger:swap_handler(tty) +        case erlang:function_exported(logger, module_info, 0) of +            false -> +                %% Old style logger had a lock-up issue and other problems related +                %% to group leader handling. +                %% enable error_logger's tty output +                error_logger:swap_handler(tty), +                %% disable the simple error_logger (which may have been added +                %% multiple times). removes at most the error_logger added by +                %% init and the error_logger added by the tty handler +                remove_error_handler(3), +                %% reset the tty handler once more for remote shells +                error_logger:swap_handler(tty); +            true -> +                %% This is no longer a problem with the logger interface +                ok +        end      catch -        E:R -> % may fail with custom loggers -            ?DEBUG("Logger changes failed for ~p:~p (~p)", [E,R,erlang:get_stacktrace()]), +        ?WITH_STACKTRACE(E,R,S) % may fail with custom loggers +            ?DEBUG("Logger changes failed for ~p:~p (~p)", [E,R,S]),              hope_for_best      end. -  setup_paths(State) ->      %% Add deps to path      code:add_pathsa(rebar_state:code_paths(State, all_deps)), @@ -235,9 +242,9 @@ maybe_run_script(State) ->              File = filename:absname(RelFile),              try run_script_file(File)              catch -                C:E -> +                ?WITH_STACKTRACE(C,E,S)                      ?ABORT("Couldn't run shell escript ~p - ~p:~p~nStack: ~p", -                           [File, C, E, erlang:get_stacktrace()]) +                           [File, C, E, S])              end      end. diff --git a/src/rebar_prv_update.erl b/src/rebar_prv_update.erl index 6dde024..1744631 100644 --- a/src/rebar_prv_update.erl +++ b/src/rebar_prv_update.erl @@ -73,8 +73,8 @@ do(State) ->                  ?PRV_ERROR({package_parse_cdn, CDN})          end      catch -        _E:C -> -            ?DEBUG("Error creating package index: ~p ~p", [C, erlang:get_stacktrace()]), +        ?WITH_STACKTRACE(_E, C, S) +            ?DEBUG("Error creating package index: ~p ~p", [C, S]),              throw(?PRV_ERROR(package_index_write))      end. diff --git a/src/rebar_state.erl b/src/rebar_state.erl index dd1f43f..3586dd6 100644 --- a/src/rebar_state.erl +++ b/src/rebar_state.erl @@ -418,9 +418,9 @@ create_logic_providers(ProviderModules, State0) ->                              end                      end, State0, ProviderModules)      catch -        C:T -> -            ?DEBUG("~p: ~p ~p", [C, T, erlang:get_stacktrace()]), -            ?CRASHDUMP("~p: ~p~n~p~n~n~p", [C, T, erlang:get_stacktrace(), State0]), +        ?WITH_STACKTRACE(C,T,S) +            ?DEBUG("~p: ~p ~p", [C, T, S]), +            ?CRASHDUMP("~p: ~p~n~p~n~n~p", [C, T, S, State0]),              throw({error, "Failed creating providers. Run with DEBUG=1 for stacktrace or consult rebar3.crashdump."})      end. diff --git a/src/rebar_utils.erl b/src/rebar_utils.erl index a911cc2..604abb8 100644 --- a/src/rebar_utils.erl +++ b/src/rebar_utils.erl @@ -506,11 +506,10 @@ otp_release1(Rel) ->              %% It's fine to rely on the binary module here because we can              %% be sure that it's available when the otp_release string does              %% not begin with $R. -            Size = byte_size(Vsn),              %% The shortest vsn string consists of at least two digits              %% followed by "\n". Therefore, it's safe to assume Size >= 3. -            case binary:part(Vsn, {Size, -3}) of -                <<"**\n">> -> +            case binary:match(Vsn, <<"**">>) of +                {Pos, _} ->                      %% The OTP documentation mentions that a system patched                      %% using the otp_patch_apply tool available to licensed                      %% customers will leave a '**' suffix in the version as a @@ -519,9 +518,9 @@ otp_release1(Rel) ->                      %% drop the suffix, given for all intents and purposes, we                      %% cannot obtain relevant information from it as far as                      %% tooling is concerned. -                    binary:bin_to_list(Vsn, {0, Size - 3}); -                _ -> -                    binary:bin_to_list(Vsn, {0, Size - 1}) +                    binary:bin_to_list(Vsn, {0, Pos}); +                nomatch -> +                    rebar_string:trim(binary:bin_to_list(Vsn), trailing, "\n")              end      end. | 
