Permalink
Browse files

Merge branch 'at/terminate-can-modify-state' into pu

* at/terminate-can-modify-state:
  Add ability for gen_(server|fsm):terminate to modify state sent to error_logger
  • Loading branch information...
2 parents 9d78f7b + aedff05 commit 4774882322c8fe0f6299cee9b6d0fb20340444d5 @bjorng bjorng committed Feb 25, 2010
@@ -668,7 +668,13 @@ gen_fsm:sync_send_all_state_event -----> Module:handle_sync_event/4
<p>This function is called by a gen_fsm when it is about to
terminate. It should be the opposite of <c>Module:init/1</c>
and do any necessary cleaning up. When it returns, the gen_fsm
- terminates with <c>Reason</c>. The return value is ignored.</p>
+ terminates with <c>Reason</c>. The return
+ value is ignored except in the special case of the function
+ returning <c>{error_info, StateData}</c> which indicates that
+ the module wants that modified state data to be passed to
+ <c>error_logger:format/2</c> instead of the original state data.</p>
+ <p><c>Reason</c> is a term denoting the stop reason and
+ <c>State</c> is the internal state of the gen_server.</p>
<p><c>Reason</c> is a term denoting the stop reason,
<c>StateName</c> is the current state name, and
<c>StateData</c> is the state data of the gen_fsm.</p>
@@ -539,7 +539,10 @@ gen_server:abcast -----> Module:handle_cast/2
terminate. It should be the opposite of <c>Module:init/1</c>
and do any necessary cleaning up. When it returns,
the gen_server terminates with <c>Reason</c>. The return
- value is ignored.</p>
+ value is ignored except in the special case of the function
+ returning <c>{error_info, State}</c> which indicates that
+ the module wants that modified state data to be passed to
+ <c>error_logger:format/2</c> instead of the original state data.</p>
<p><c>Reason</c> is a term denoting the stop reason and
<c>State</c> is the internal state of the gen_server.</p>
<p><c>Reason</c> depends on why the gen_server is terminating.
View
@@ -533,7 +533,7 @@ terminate(Reason, Name, Msg, Mod, StateName, StateData, Debug) ->
{'EXIT', R} ->
error_info(R, Name, Msg, StateName, StateData, Debug),
exit(R);
- _ ->
+ Res ->
case Reason of
normal ->
exit(normal);
@@ -542,7 +542,14 @@ terminate(Reason, Name, Msg, Mod, StateName, StateData, Debug) ->
{shutdown,_}=Shutdown ->
exit(Shutdown);
_ ->
- error_info(Reason, Name, Msg, StateName, StateData, Debug),
+ ErrorStateData =
+ case Res of
+ {error_info, NewStateData} ->
+ NewStateData;
+ _ ->
+ StateData
+ end,
+ error_info(Reason, Name, Msg, StateName, ErrorStateData, Debug),
exit(Reason)
end
end.
@@ -696,7 +696,7 @@ terminate(Reason, Name, Msg, Mod, State, Debug) ->
{'EXIT', R} ->
error_info(R, Name, Msg, State, Debug),
exit(R);
- _ ->
+ Res ->
case Reason of
normal ->
exit(normal);
@@ -705,7 +705,14 @@ terminate(Reason, Name, Msg, Mod, State, Debug) ->
{shutdown,_}=Shutdown ->
exit(Shutdown);
_ ->
- error_info(Reason, Name, Msg, State, Debug),
+ ErrorState =
+ case Res of
+ {error_info, NewState} ->
+ NewState;
+ _ ->
+ State
+ end,
+ error_info(Reason, Name, Msg, ErrorState, Debug),
exit(Reason)
end
end.

0 comments on commit 4774882

Please sign in to comment.