From 12d2a6f5c6a00ffd6907ca09811e5695d75c024c Mon Sep 17 00:00:00 2001 From: Andrew Thompson Date: Sun, 31 Dec 2017 11:52:50 -0800 Subject: [PATCH] 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. --- src/error_logger_lager_h.erl | 8 +++++--- test/crash.erl | 3 +++ test/lager_test_backend.erl | 1 + 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/error_logger_lager_h.erl b/src/error_logger_lager_h.erl index 6866496..af0afa1 100644 --- a/src/error_logger_lager_h.erl +++ b/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])}. diff --git a/test/crash.erl b/test/crash.erl index bb871c9..560b17e 100644 --- a/test/crash.erl +++ b/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), diff --git a/test/lager_test_backend.erl b/test/lager_test_backend.erl index a055c4e..fb7dd80 100644 --- a/test/lager_test_backend.erl +++ b/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", [