summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFred Hebert <mononcqc@ferd.ca>2018-05-03 07:12:11 -0400
committerFred Hebert <mononcqc@ferd.ca>2018-05-03 07:18:04 -0400
commit5f9b4293bc029e2132d7c442cb5b4480915ea0e4 (patch)
tree8ba1730e313f0fe955c0f366ef4ee870997d9275 /src
parentfb87ed576203c303911193b4902e661c59188274 (diff)
Work around OTP-21 deprecation of get_stacktrace()
Based off a macro by @okeuday at https://github.com/erlang/otp/pull/1783
Diffstat (limited to 'src')
-rw-r--r--src/rebar.hrl6
-rw-r--r--src/rebar3.erl21
-rw-r--r--src/rebar_agent.erl4
-rw-r--r--src/rebar_core.erl3
-rw-r--r--src/rebar_dialyzer_format.erl4
-rw-r--r--src/rebar_fetch.erl4
-rw-r--r--src/rebar_plugins.erl4
-rw-r--r--src/rebar_prv_shell.erl8
-rw-r--r--src/rebar_prv_update.erl4
-rw-r--r--src/rebar_state.erl6
10 files changed, 34 insertions, 30 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..d62f1bc 100644
--- a/src/rebar_prv_shell.erl
+++ b/src/rebar_prv_shell.erl
@@ -210,8 +210,8 @@ rewrite_leaders(OldUser, NewUser) ->
%% reset the tty handler once more for remote shells
error_logger:swap_handler(tty)
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.
@@ -235,9 +235,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.