Browse Source

Handle uncaught throws in a gen_* process better

pull/62/head
Andrew Thompson 13 years ago
parent
commit
fad809bed4
3 changed files with 14 additions and 0 deletions
  1. +3
    -0
      src/error_logger_lager_h.erl
  2. +2
    -0
      test/crash.erl
  3. +9
    -0
      test/lager_test_backend.erl

+ 3
- 0
src/error_logger_lager_h.erl View File

@ -274,6 +274,9 @@ format_mfa({M, F, A, Props}) when is_list(Props) ->
Line ->
[format_mfa({M, F, A}), io_lib:format(" line ~w", [Line])]
end;
format_mfa([{M, F, A, Props}, _]) when is_list(Props) ->
%% this kind of weird stacktrace can be generated by a uncaught throw in a gen_server
format_mfa({M, F, A, Props});
format_mfa(Other) ->
io_lib:format("~w", [Other]).

+ 2
- 0
test/crash.erl View File

@ -85,6 +85,8 @@ handle_call(badarity, _, State) ->
F = fun(A, B, C) -> A + B + C end,
Res = F(State),
{reply, Res, State};
handle_call(throw, _, State) ->
throw(a_ball);
handle_call(_Call, _From, State) ->
{reply, ok, State}.

+ 9
- 0
test/lager_test_backend.erl View File

@ -305,6 +305,15 @@ error_logger_redirect_crash_test_() ->
?assertEqual(Expected, lists:flatten(Msg))
end
},
{"bad return value uncaught throw",
fun() ->
Pid = whereis(crash),
crash(throw),
{_, _, Msg} = pop(),
Expected = lists:flatten(io_lib:format("[error] ~w gen_server crash terminated with reason: bad return value: a_ball", [Pid])),
?assertEqual(Expected, lists:flatten(Msg))
end
},
{"case clause",
fun() ->
Pid = whereis(crash),

Loading…
Cancel
Save