Skip to content

Commit

Permalink
Better crash reports for processes started via proc_lib, Fixes erlang…
Browse files Browse the repository at this point in the history
  • Loading branch information
Vagabond committed Dec 15, 2011
1 parent 5fd47ad commit c21f1bd
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/error_logger_lager_h.erl
Expand Up @@ -159,9 +159,15 @@ format_crash_report(Report, Neighbours) ->
proplists:get_value(pid, Report);
Atom -> Atom
end,
{_Class, Reason, _Trace} = proplists:get_value(error_info, Report),
{_Class, Reason, Trace} = proplists:get_value(error_info, Report),
ReasonStr = case is_atom(Reason) of
true ->
format_reason({Reason, Trace});
_ ->
format_reason(Reason)
end,
io_lib:format("Process ~w with ~w neighbours crashed with reason: ~s",
[Name, length(Neighbours), format_reason(Reason)]).
[Name, length(Neighbours), ReasonStr]).

format_offender(Off) ->
case proplists:get_value(mfargs, Off) of
Expand Down
13 changes: 13 additions & 0 deletions test/lager_test_backend.erl
Expand Up @@ -685,6 +685,19 @@ error_logger_redirect_test_() ->
?assert(length(lists:flatten(Msg)) < 650)
end
},
{"crash reports for 'special processes' should be handled right",
fun() ->
{ok, Pid} = special_process:start(),
unlink(Pid),
Pid ! function_clause,
timer:sleep(500),
_ = gen_event:which_handlers(error_logger),
{_, _, Msg} = pop(),
Expected = lists:flatten(io_lib:format("[error] ~p CRASH REPORT Process ~p with 0 neighbours crashed with reason: no function clause matching special_process:foo(bar)",
[Pid, Pid])),
?assertEqual(Expected, lists:flatten(Msg))
end
},
{"messages should not be generated if they don't satisfy the threshold",
fun() ->
lager:set_loglevel(?MODULE, error),
Expand Down
28 changes: 28 additions & 0 deletions test/special_process.erl
@@ -0,0 +1,28 @@
-module(special_process).
-export([start/0, init/1]).

start() ->
proc_lib:start_link(?MODULE, init, [self()]).

init(Parent) ->
proc_lib:init_ack(Parent, {ok, self()}),
loop().

loop() ->
receive
function_clause ->
foo(bar),
loop();
exit ->
exit(byebye),
loop();
error ->
erlang:error(mybad),
loop();
_ ->
loop()
end.

foo(baz) ->
ok.

0 comments on commit c21f1bd

Please sign in to comment.