@@ -1150,14 +1150,15 @@ print_event(Dev, Event, Name) ->
1150
1150
1151
1151
terminate (Reason , Msg , # gs2_state { name = Name ,
1152
1152
mod = Mod ,
1153
- state = State ,
1153
+ state = ModState0 ,
1154
1154
debug = Debug ,
1155
1155
stop_stats_fun = StopStatsFun
1156
1156
} = GS2State ) ->
1157
1157
StopStatsFun (stop_stats_timer (GS2State )),
1158
- case catch Mod :terminate (Reason , State ) of
1158
+ case catch Mod :terminate (Reason , ModState0 ) of
1159
1159
{'EXIT' , R } ->
1160
- error_info (R , Reason , Name , Msg , State , Debug ),
1160
+ ModState1 = maybe_format_state (Mod , ModState0 ),
1161
+ error_info (R , Reason , Name , Msg , ModState1 , Debug ),
1161
1162
exit (R );
1162
1163
_ ->
1163
1164
case Reason of
@@ -1168,28 +1169,37 @@ terminate(Reason, Msg, #gs2_state { name = Name,
1168
1169
{shutdown ,_ }= Shutdown ->
1169
1170
exit (Shutdown );
1170
1171
_ ->
1171
- error_info (Reason , undefined , Name , Msg , State , Debug ),
1172
+ ModState1 = maybe_format_state (Mod , ModState0 ),
1173
+ error_info (Reason , undefined , Name , Msg , ModState1 , Debug ),
1172
1174
exit (Reason )
1173
1175
end
1174
1176
end .
1175
1177
1178
+ maybe_format_state (M , ModState ) ->
1179
+ case erlang :function_exported (M , format_state , 1 ) of
1180
+ true ->
1181
+ M :format_state (ModState );
1182
+ false ->
1183
+ ModState
1184
+ end .
1185
+
1176
1186
error_info (_Reason , _RootCause , application_controller , _Msg , _State , _Debug ) ->
1177
1187
% % OTP-5811 Don't send an error report if it's the system process
1178
1188
% % application_controller which is terminating - let init take care
1179
1189
% % of it instead
1180
1190
ok ;
1181
- error_info (Reason , RootCause , Name , Msg , State , Debug ) ->
1191
+ error_info (Reason , RootCause , Name , Msg , ModState , Debug ) ->
1182
1192
Reason1 = error_reason (Reason ),
1183
1193
Fmt =
1184
1194
" ** Generic server ~tp terminating~n "
1185
1195
" ** Last message in was ~tp~n "
1186
1196
" ** When Server state == ~tp~n "
1187
1197
" ** Reason for termination == ~n ** ~tp~n " ,
1188
1198
case RootCause of
1189
- undefined -> format (Fmt , [Name , Msg , State , Reason1 ]);
1199
+ undefined -> format (Fmt , [Name , Msg , ModState , Reason1 ]);
1190
1200
_ -> format (Fmt ++ " ** In 'terminate' callback "
1191
1201
" with reason ==~n ** ~tp~n " ,
1192
- [Name , Msg , State , Reason1 ,
1202
+ [Name , Msg , ModState , Reason1 ,
1193
1203
error_reason (RootCause )])
1194
1204
end ,
1195
1205
sys :print_log (Debug ),
0 commit comments