Преглед на файлове

Merge pull request #1080 from project-fifo/crashdump

Write rebar3.crashdump on errors
pull/978/merge
Fred Hebert преди 9 години
committed by GitHub
родител
ревизия
979bb18b27
променени са 4 файла, в които са добавени 19 реда и са изтрити 3 реда
  1. +1
    -0
      src/rebar.hrl
  2. +4
    -2
      src/rebar3.erl
  3. +12
    -0
      src/rebar_log.erl
  4. +2
    -1
      src/rebar_state.erl

+ 1
- 0
src/rebar.hrl Целия файл

@ -10,6 +10,7 @@
-define(INFO(Str, Args), rebar_log:log(info, Str, Args)). -define(INFO(Str, Args), rebar_log:log(info, Str, Args)).
-define(WARN(Str, Args), rebar_log:log(warn, Str, Args)). -define(WARN(Str, Args), rebar_log:log(warn, Str, Args)).
-define(ERROR(Str, Args), rebar_log:log(error, 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))). -define(FMT(Str, Args), lists:flatten(io_lib:format(Str, Args))).

+ 4
- 2
src/rebar3.erl Целия файл

@ -272,7 +272,8 @@ handle_error({error, rebar_abort}) ->
handle_error({error, {Module, Reason}}) -> handle_error({error, {Module, Reason}}) ->
case code:which(Module) of case code:which(Module) of
non_existing -> 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]), ?DEBUG("Uncaught error: ~p ~p", [Module, Reason]),
?INFO("When submitting a bug report, please include the output of `rebar3 report \"your command\"`", []); ?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) -> handle_error(Error) ->
%% Nothing should percolate up from rebar_core; %% Nothing should percolate up from rebar_core;
%% Dump this error to console %% 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]), ?DEBUG("Uncaught error: ~p", [Error]),
case erlang:get_stacktrace() of case erlang:get_stacktrace() of
[] -> ok; [] -> ok;

+ 12
- 0
src/rebar_log.erl Целия файл

@ -27,6 +27,7 @@
-module(rebar_log). -module(rebar_log).
-export([init/2, -export([init/2,
crashdump/2,
set_level/1, set_level/1,
get_level/0, get_level/0,
error_level/0, error_level/0,
@ -73,6 +74,7 @@ init(Caller, Verbosity) ->
?DEBUG_LEVEL -> debug ?DEBUG_LEVEL -> debug
end, end,
Intensity = intensity(), Intensity = intensity(),
application:set_env(rebar, log_caller, Caller),
Log = ec_cmd_log:new(Level, Caller, Intensity), Log = ec_cmd_log:new(Level, Caller, Intensity),
set_level(valid_level(Verbosity)), set_level(valid_level(Verbosity)),
application:set_env(rebar, log, Log). application:set_env(rebar, log, Log).
@ -95,6 +97,16 @@ log(Level, Str, Args) ->
{ok, LogState} = application:get_env(rebar, log), {ok, LogState} = application:get_env(rebar, log),
ec_cmd_log:Level(LogState, Str++"~n", Args). 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. error_level() -> ?ERROR_LEVEL.
default_level() -> ?INFO_LEVEL. default_level() -> ?INFO_LEVEL.

+ 2
- 1
src/rebar_state.erl Целия файл

@ -417,7 +417,8 @@ create_logic_providers(ProviderModules, State0) ->
catch catch
C:T -> C:T ->
?DEBUG("~p: ~p ~p", [C, T, erlang:get_stacktrace()]), ?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. end.
to_list(#state_t{} = State) -> to_list(#state_t{} = State) ->

Зареждане…
Отказ
Запис