summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHeinz N. Gies <heinz@licenser.net>2016-02-25 22:26:58 -0500
committerHeinz N. Gies <heinz@licenser.net>2016-04-16 02:45:38 +0200
commit5945251fc032465b1eb609fee16efa52a9854a5a (patch)
tree3d99dcc6bd457d304456d65cede78b386c151d54 /src
parentbc9746881f58171b91cdc9c6494299b3856e21fe (diff)
Make sure not to dump in api mode
Diffstat (limited to 'src')
-rw-r--r--src/rebar.hrl1
-rw-r--r--src/rebar3.erl6
-rw-r--r--src/rebar_log.erl12
-rw-r--r--src/rebar_state.erl4
4 files changed, 18 insertions, 5 deletions
diff --git a/src/rebar.hrl b/src/rebar.hrl
index f4e7f5e..c96b191 100644
--- a/src/rebar.hrl
+++ b/src/rebar.hrl
@@ -10,6 +10,7 @@
-define(INFO(Str, Args), rebar_log:log(info, Str, Args)).
-define(WARN(Str, Args), rebar_log:log(warn, Str, Args)).
-define(ERROR(Str, Args), rebar_log:log(error, Str, Args)).
+-define(CRASHDUMP(Str, Args), rebar_log:crashdump(Str, Args)).
-define(FMT(Str, Args), lists:flatten(io_lib:format(Str, Args))).
diff --git a/src/rebar3.erl b/src/rebar3.erl
index 75eefa0..4564b8a 100644
--- a/src/rebar3.erl
+++ b/src/rebar3.erl
@@ -265,8 +265,8 @@ handle_error({error, rebar_abort}) ->
handle_error({error, {Module, Reason}}) ->
case code:which(Module) of
non_existing ->
- file:write_file("rebar3.crashdump", io_lib:fwrite("~p: ~p~n~p~n~n", [Module, Reason, erlang:get_stacktrace()])),
- ?ERROR("Uncaught error in rebar_core. Run with DEBUG=1 to see stacktrace rebar3.crashdump", []),
+ ?CRASHDUMP("~p: ~p~n~p~n~n", [Module, Reason, erlang:get_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\"`", []);
_ ->
@@ -279,7 +279,7 @@ handle_error({error, Error}) when is_list(Error) ->
handle_error(Error) ->
%% Nothing should percolate up from rebar_core;
%% Dump this error to console
- file:write_file("rebar3.crashdump", io_lib:fwrite("Error: ~p~n~p~n~n", [Error, erlang:get_stacktrace()])),
+ ?CRASHDUMP("Error: ~p~n~p~n~n", [Error, erlang:get_stacktrace()]),
?ERROR("Uncaught error in rebar_core. Run with DEBUG=1 to see stacktrace or consult rebar3.crashdump", []),
?DEBUG("Uncaught error: ~p", [Error]),
case erlang:get_stacktrace() of
diff --git a/src/rebar_log.erl b/src/rebar_log.erl
index 23ae81e..b1a70c2 100644
--- a/src/rebar_log.erl
+++ b/src/rebar_log.erl
@@ -27,6 +27,7 @@
-module(rebar_log).
-export([init/2,
+ crashdump/2,
set_level/1,
get_level/0,
error_level/0,
@@ -73,6 +74,7 @@ init(Caller, Verbosity) ->
?DEBUG_LEVEL -> debug
end,
Intensity = intensity(),
+ application:set_env(rebar, log_caller, Caller),
Log = ec_cmd_log:new(Level, Caller, Intensity),
set_level(valid_level(Verbosity)),
application:set_env(rebar, log, Log).
@@ -95,6 +97,16 @@ log(Level, Str, Args) ->
{ok, LogState} = application:get_env(rebar, log),
ec_cmd_log:Level(LogState, Str++"~n", Args).
+crashdump(Str, Args) ->
+ crashdump("rebar3.crashdump", Str, Args).
+crashdump(File, Str, Args) ->
+ case application:get_env(rebar, log_caller) of
+ {ok, api} ->
+ ok;
+ _ ->
+ file:write_file(File, io_lib:fwrite(Str, Args))
+ end.
+
error_level() -> ?ERROR_LEVEL.
default_level() -> ?INFO_LEVEL.
diff --git a/src/rebar_state.erl b/src/rebar_state.erl
index f438700..bdd4aeb 100644
--- a/src/rebar_state.erl
+++ b/src/rebar_state.erl
@@ -417,8 +417,8 @@ create_logic_providers(ProviderModules, State0) ->
catch
C:T ->
?DEBUG("~p: ~p ~p", [C, T, erlang:get_stacktrace()]),
- file:write_file("rebar3.crashdump", io_lib:fwrite("~p: ~p~n~p~n~n~p", [C, T, erlang:get_stacktrace(), State0])),
- throw({error, "Failed creating providers. Run with DEBUG=1 for stacktrace rebar3.crashdump."})
+ ?CRASHDUMP("~p: ~p~n~p~n~n~p", [C, T, erlang:get_stacktrace(), State0]),
+ throw({error, "Failed creating providers. Run with DEBUG=1 for stacktrace or consult rebar3.crashdump."})
end.
to_list(#state_t{} = State) ->