Преглед изворни кода

Handle yet another stacktrace form

Sometimes the stacktrace is a larger array of {M, F, A, Prop} tuples.
The handler code was expecting at most 2 tuples in the list. Relax this
requirement and add a test that provokes this edge-case.
pull/429/head
Andrew Thompson пре 7 година
родитељ
комит
12d2a6f5c6
3 измењених фајлова са 9 додато и 3 уклоњено
  1. +5
    -3
      src/error_logger_lager_h.erl
  2. +3
    -0
      test/crash.erl
  3. +1
    -0
      test/lager_test_backend.erl

+ 5
- 3
src/error_logger_lager_h.erl Прегледај датотеку

@ -500,7 +500,7 @@ format_reason_md({{badarity, {Fun, Args}}, [MFA|_]}) ->
[length(Args), Arity]), Formatted]};
format_reason_md({noproc, MFA}) ->
{Md, Formatted} = format_mfa_md(MFA),
{[{reason, badarity} | Md],
{[{reason, noproc} | Md],
["no such process or port in call to ", Formatted]};
format_reason_md({{badfun, Term}, [MFA|_]}) ->
{Md, Formatted} = format_mfa_md(MFA),
@ -537,11 +537,13 @@ format_mfa_md({M, F, A, Props}) when is_list(Props) ->
{Md, Formatted} = format_mfa_md({M, F, A}),
{[{line, Line} | Md], [Formatted, io_lib:format(" line ~w", [Line])]}
end;
format_mfa_md([{M, F, A}, _]) ->
format_mfa_md([{M, F, A}| _]) ->
%% this kind of weird stacktrace can be generated by a uncaught throw in a gen_server
format_mfa_md({M, F, A});
format_mfa_md([{M, F, A, Props}, _]) when is_list(Props) ->
format_mfa_md([{M, F, A, Props}| _]) when is_list(Props) ->
%% this kind of weird stacktrace can be generated by a uncaught throw in a gen_server
%% TODO we might not always want to print the first MFA we see here, often it is more helpful
%% to print a lower one, but it is hard to programatically decide.
format_mfa_md({M, F, A, Props});
format_mfa_md(Other) ->
{[], io_lib:format("~w", [Other])}.

+ 3
- 0
test/crash.erl Прегледај датотеку

@ -81,6 +81,9 @@ handle_call(port_limit, _, State) ->
handle_call(noproc, _, State) ->
Res = gen_event:call(foo, bar, baz),
{reply, Res, State};
handle_call(noproc_proc_lib, _, State) ->
Res = proc_lib:stop(foo),
{reply, Res, State};
handle_call(badarity, _, State) ->
F = fun(A, B, C) -> A + B + C end,
Res = F(State),

+ 1
- 0
test/lager_test_backend.erl Прегледај датотеку

@ -1107,6 +1107,7 @@ error_logger_redirect_crash_test_() ->
TestBody("bad arg2",badarg2,"gen_server crash terminated with reason: bad argument in call to erlang:iolist_to_binary([\"foo\",bar]) in crash:handle_call/3"),
TestBody("bad record",badrecord,"gen_server crash terminated with reason: bad record state in crash:handle_call/3"),
TestBody("noproc",noproc,"gen_server crash terminated with reason: no such process or port in call to gen_event:call(foo, bar, baz)"),
TestBody("noproc_proc_lib",noproc_proc_lib,"gen_server crash terminated with reason: no such process or port in call to proc_lib:stop/3"),
TestBody("badfun",badfun,"gen_server crash terminated with reason: bad function booger in crash:handle_call/3")
],
{"Error logger redirect crash", [

Loading…
Откажи
Сачувај