Permalink
Browse files

Merge pull request #22 from basho/adt-fix-crash-report-process-names

Fix how the name/pid of the process is printed in crash reports
  • Loading branch information...
2 parents 1d7b690 + de5d84e commit 2b6027dc86f937cdc13254ef72abebe1244910ff @Vagabond Vagabond committed Sep 23, 2011
Showing with 13 additions and 8 deletions.
  1. +6 −1 src/error_logger_lager_h.erl
  2. +7 −7 test/lager_test_backend.erl
@@ -153,7 +153,12 @@ code_change(_OldVsn, State, _Extra) ->
%% internal functions
format_crash_report(Report, Neighbours) ->
- Name = proplists:get_value(registered_name, Report, proplists:get_value(pid, Report)),
+ Name = case proplists:get_value(registered_name, Report, []) of
+ [] ->
+ %% process_info(Pid, registered_name) returns [] for unregistered processes
+ proplists:get_value(pid, Report);
+ Atom -> Atom
+ end,
{_Class, Reason, _Trace} = proplists:get_value(error_info, Report),
io_lib:format("Process ~w with ~w neighbours crashed with reason: ~s",
[Name, length(Neighbours), format_reason(Reason)]).
@@ -575,7 +575,7 @@ error_logger_redirect_test_() ->
},
{"crash report for emfile",
fun() ->
- sync_error_logger:error_report(crash_report, [[{pid, self()}, {error_info, {error, {emfile, [{stack, trace, 1}]}, []}}], []]),
+ sync_error_logger:error_report(crash_report, [[{pid, self()}, {registered_name, []}, {error_info, {error, {emfile, [{stack, trace, 1}]}, []}}], []]),
_ = gen_event:which_handlers(error_logger),
{_, _, Msg} = pop(),
Expected = lists:flatten(io_lib:format("[error] ~w CRASH REPORT Process ~w with 0 neighbours crashed with reason: maximum number of file descriptors exhausted, check ulimit -n", [self(), self()])),
@@ -584,7 +584,7 @@ error_logger_redirect_test_() ->
},
{"crash report for system process limit",
fun() ->
- sync_error_logger:error_report(crash_report, [[{pid, self()}, {error_info, {error, {system_limit, [{erlang, spawn, 1}]}, []}}], []]),
+ sync_error_logger:error_report(crash_report, [[{pid, self()}, {registered_name, []}, {error_info, {error, {system_limit, [{erlang, spawn, 1}]}, []}}], []]),
_ = gen_event:which_handlers(error_logger),
{_, _, Msg} = pop(),
Expected = lists:flatten(io_lib:format("[error] ~w CRASH REPORT Process ~w with 0 neighbours crashed with reason: system limit: maximum number of processes exceeded", [self(), self()])),
@@ -593,7 +593,7 @@ error_logger_redirect_test_() ->
},
{"crash report for system process limit2",
fun() ->
- sync_error_logger:error_report(crash_report, [[{pid, self()}, {error_info, {error, {system_limit, [{erlang, spawn_opt, 1}]}, []}}], []]),
+ sync_error_logger:error_report(crash_report, [[{pid, self()}, {registered_name, []}, {error_info, {error, {system_limit, [{erlang, spawn_opt, 1}]}, []}}], []]),
_ = gen_event:which_handlers(error_logger),
{_, _, Msg} = pop(),
Expected = lists:flatten(io_lib:format("[error] ~w CRASH REPORT Process ~w with 0 neighbours crashed with reason: system limit: maximum number of processes exceeded", [self(), self()])),
@@ -602,7 +602,7 @@ error_logger_redirect_test_() ->
},
{"crash report for system port limit",
fun() ->
- sync_error_logger:error_report(crash_report, [[{pid, self()}, {error_info, {error, {system_limit, [{erlang, open_port, 1}]}, []}}], []]),
+ sync_error_logger:error_report(crash_report, [[{pid, self()}, {registered_name, []}, {error_info, {error, {system_limit, [{erlang, open_port, 1}]}, []}}], []]),
_ = gen_event:which_handlers(error_logger),
{_, _, Msg} = pop(),
Expected = lists:flatten(io_lib:format("[error] ~w CRASH REPORT Process ~w with 0 neighbours crashed with reason: system limit: maximum number of ports exceeded", [self(), self()])),
@@ -611,7 +611,7 @@ error_logger_redirect_test_() ->
},
{"crash report for system port limit",
fun() ->
- sync_error_logger:error_report(crash_report, [[{pid, self()}, {error_info, {error, {system_limit, [{erlang, list_to_atom, 1}]}, []}}], []]),
+ sync_error_logger:error_report(crash_report, [[{pid, self()}, {registered_name, []}, {error_info, {error, {system_limit, [{erlang, list_to_atom, 1}]}, []}}], []]),
_ = gen_event:which_handlers(error_logger),
{_, _, Msg} = pop(),
Expected = lists:flatten(io_lib:format("[error] ~w CRASH REPORT Process ~w with 0 neighbours crashed with reason: system limit: tried to create an atom larger than 255, or maximum atom count exceeded", [self(), self()])),
@@ -620,10 +620,10 @@ error_logger_redirect_test_() ->
},
{"crash report for system ets table limit",
fun() ->
- sync_error_logger:error_report(crash_report, [[{pid, self()}, {error_info, {error, {system_limit,[{ets,new,[segment_offsets,[ordered_set,public]]},{mi_segment,open_write,1},{mi_buffer_converter,handle_cast,2},{gen_server,handle_msg,5},{proc_lib,init_p_do_apply,3}]}, []}}], []]),
+ sync_error_logger:error_report(crash_report, [[{pid, self()}, {registered_name, test}, {error_info, {error, {system_limit,[{ets,new,[segment_offsets,[ordered_set,public]]},{mi_segment,open_write,1},{mi_buffer_converter,handle_cast,2},{gen_server,handle_msg,5},{proc_lib,init_p_do_apply,3}]}, []}}], []]),
_ = gen_event:which_handlers(error_logger),
{_, _, Msg} = pop(),
- Expected = lists:flatten(io_lib:format("[error] ~w CRASH REPORT Process ~w with 0 neighbours crashed with reason: system limit: maximum number of ETS tables exceeded", [self(), self()])),
+ Expected = lists:flatten(io_lib:format("[error] ~w CRASH REPORT Process ~w with 0 neighbours crashed with reason: system limit: maximum number of ETS tables exceeded", [self(), test])),
?assertEqual(Expected, lists:flatten(Msg))
end
},

0 comments on commit 2b6027d

Please sign in to comment.