summaryrefslogtreecommitdiff
path: root/src/gen_server2.erl
diff options
context:
space:
mode:
authorMatthias Radestock <matthias@rabbitmq.com>2010-08-26 21:31:49 +0100
committerMatthias Radestock <matthias@rabbitmq.com>2010-08-26 21:31:49 +0100
commit9dfff4665670f0375d7626a319c13dd272dd411b (patch)
tree8083358709b3c2f299645761e7d01121f0da0a90 /src/gen_server2.erl
parentf889429e537562677f3bd0a75162ec1a01114c42 (diff)
downloadrabbitmq-server-9dfff4665670f0375d7626a319c13dd272dd411b.tar.gz
report the root cause when 'terminate' callback fails
Diffstat (limited to 'src/gen_server2.erl')
-rw-r--r--src/gen_server2.erl53
1 files changed, 27 insertions, 26 deletions
diff --git a/src/gen_server2.erl b/src/gen_server2.erl
index f1c8eb4d..0365b68e 100644
--- a/src/gen_server2.erl
+++ b/src/gen_server2.erl
@@ -976,7 +976,7 @@ print_event(Dev, Event, Name) ->
terminate(Reason, Name, Msg, Mod, State, Debug) ->
case catch Mod:terminate(Reason, State) of
{'EXIT', R} ->
- error_info(R, Name, Msg, State, Debug),
+ error_info(R, Reason, Name, Msg, State, Debug),
exit(R);
_ ->
case Reason of
@@ -987,42 +987,43 @@ terminate(Reason, Name, Msg, Mod, State, Debug) ->
{shutdown,_}=Shutdown ->
exit(Shutdown);
_ ->
- error_info(Reason, Name, Msg, State, Debug),
+ error_info(Reason, undefined, Name, Msg, State, Debug),
exit(Reason)
end
end.
-error_info(_Reason, application_controller, _Msg, _State, _Debug) ->
+error_info(_Reason, _RootCause, application_controller, _Msg, _State, _Debug) ->
%% OTP-5811 Don't send an error report if it's the system process
%% application_controller which is terminating - let init take care
%% of it instead
ok;
-error_info(Reason, Name, Msg, State, Debug) ->
- Reason1 =
- case Reason of
- {undef,[{M,F,A}|MFAs]} ->
- case code:is_loaded(M) of
- false ->
- {'module could not be loaded',[{M,F,A}|MFAs]};
- _ ->
- case erlang:function_exported(M, F, length(A)) of
- true ->
- Reason;
- false ->
- {'function not exported',[{M,F,A}|MFAs]}
- end
- end;
- _ ->
- Reason
- end,
- format("** Generic server ~p terminating \n"
- "** Last message in was ~p~n"
- "** When Server state == ~p~n"
- "** Reason for termination == ~n** ~p~n",
- [Name, Msg, State, Reason1]),
+error_info(Reason, RootCause, Name, Msg, State, Debug) ->
+ Reason1 = error_reason(Reason),
+ Fmt =
+ "** Generic server ~p terminating~n"
+ "** Last message in was ~p~n"
+ "** When Server state == ~p~n"
+ "** Reason for termination == ~n** ~p~n",
+ case RootCause of
+ undefined -> format(Fmt, [Name, Msg, State, Reason1]);
+ _ -> format(Fmt ++ "** Root cause for termination ==~n** ~p~n",
+ [Name, Msg, State, Reason1,
+ error_reason(RootCause)])
+ end,
sys:print_log(Debug),
ok.
+error_reason({undef,[{M,F,A}|MFAs]} = Reason) ->
+ case code:is_loaded(M) of
+ false -> {'module could not be loaded',[{M,F,A}|MFAs]};
+ _ -> case erlang:function_exported(M, F, length(A)) of
+ true -> Reason;
+ false -> {'function not exported',[{M,F,A}|MFAs]}
+ end
+ end;
+error_reason(Reason) ->
+ Reason.
+
%%% ---------------------------------------------------
%%% Misc. functions.
%%% ---------------------------------------------------