diff options
| -rw-r--r-- | src/rebar.hrl | 1 | ||||
| -rw-r--r-- | src/rebar3.erl | 6 | ||||
| -rw-r--r-- | src/rebar_log.erl | 12 | ||||
| -rw-r--r-- | src/rebar_state.erl | 3 | 
4 files changed, 19 insertions, 3 deletions
| diff --git a/src/rebar.hrl b/src/rebar.hrl index 0b7f0b1..4d69c7b 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 a1e2975..82b4472 100644 --- a/src/rebar3.erl +++ b/src/rebar3.erl @@ -272,7 +272,8 @@ handle_error({error, rebar_abort}) ->  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", []), +            ?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\"`", []);          _ -> @@ -285,7 +286,8 @@ handle_error({error, Error}) when is_list(Error) ->  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", []), +    ?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          [] -> ok; 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 a613a00..bdd4aeb 100644 --- a/src/rebar_state.erl +++ b/src/rebar_state.erl @@ -417,7 +417,8 @@ create_logic_providers(ProviderModules, State0) ->      catch          C:T ->              ?DEBUG("~p: ~p ~p", [C, T, erlang:get_stacktrace()]), -            throw({error, "Failed creating providers. Run with DEBUG=1 for stacktrace."}) +            ?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) -> | 
