[erlang-patches] format_status analog for error_info
Andrew Thompson
andrew@REDACTED
Thu Feb 25 15:53:30 CET 2010
On Thu, Feb 25, 2010 at 02:25:17AM -0500, Steve Vinoski wrote:
> Sure, I think that would work. Only sys.erl currently initiates a call to
> format_status, so only the atom 'normal' is currently ever passed. A
> possible patch for gen_server.erl, for example, to reuse format_status for
> error printing might look like this (this is just an example, not intended
> an official patch submission):
>
> diff --git a/lib/stdlib/src/gen_server.erl b/lib/stdlib/src/gen_server.erl
> index f1a9a31..f4ab898 100644
> --- a/lib/stdlib/src/gen_server.erl
> +++ b/lib/stdlib/src/gen_server.erl
> @@ -705,7 +705,18 @@ terminate(Reason, Name, Msg, Mod, State, Debug) ->
> {shutdown,_}=Shutdown ->
> exit(Shutdown);
> _ ->
> - error_info(Reason, Name, Msg, State, Debug),
> + NState =
> + case erlang:function_exported(Mod, format_status,
> 2) of
> + true ->
> + FmtArgs = [get(), State],
> + case catch Mod:format_status(error,
> FmtArgs) of
> + {'EXIT', _} -> State;
> + Else -> Else
> + end;
> + _ ->
> + State
> + end,
> + error_info(Reason, Name, Msg, NState, Debug),
> exit(Reason)
> end
> end.
>
So in this case, format_status when the first argument is 'error' is
expected to return something more like the passed in state data rather
than the {data, [{"State", State}]} structure? (although I guess it
doesn't really matter since its printed by ~p anyway).
> I think this could work pretty well. Shall I work up an official patch?
Yeah, go for it and maybe we can get some feedback on which way the OTP
team prefers.
Andrew
More information about the erlang-patches
mailing list