From 5dcc05d56a00851a2d4f956fa34267576b0e2d75 Mon Sep 17 00:00:00 2001 From: Jarvis Carroll Date: Tue, 12 May 2026 06:00:26 +0000 Subject: [PATCH] Change fate_to_erlang warning This warning always confuses me. Usually it is a case I haven't actually implemented, but I don't need the program to diagnose that for me, I need the program to tell me what the type was, so that I can work out why it thinks it isn't implemented. All three terms of the annotated type are relevant, but the annotated version can only differ from the normalized version if it is a record or variant definition, so we special case those two just to communicate that the fact that it is *some* kind of record did successfully pass through to the coerce logic, and otherwise we just try and print the opaque and normalized types faithfully. --- src/hz_aaci.erl | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/src/hz_aaci.erl b/src/hz_aaci.erl index 4aa095d..1313b9b 100644 --- a/src/hz_aaci.erl +++ b/src/hz_aaci.erl @@ -944,15 +944,30 @@ fate_to_erlang({O, N, {unknown_type, _}}, Data) -> io:format(Message, [O, N, Data]) end, {ok, Data}; -fate_to_erlang({O, N, _}, Data) -> - case N of - already_normalized -> - io:format("Warning: Unimplemented type ~p.~nUsing term as is:~n~p~n", [O, Data]); - _ -> - io:format("Warning: Unimplemented type ~p (i.e. ~p).~nUsing term as is:~n~p~n", [O, N, Data]) - end, +fate_to_erlang(Type, Data) -> + TypeStr = type_to_iolist(Type), + io:format("Warning: Could not coerce term into ~s. Using term as is: ~p~n", [TypeStr, Data]), {ok, Data}. +type_to_iolist({O, already_normalized, S}) -> + % Already normalized. Example output: + % type {map, [string, integer]} + opaque_type_to_iolist(O, S); +type_to_iolist({O, N, S}) -> + % Type alias. Print the alias, and then print the normalized version in + % parentheses. Example output: + % type "my_alias" (i.e. record type {"my_record_type", [integer]}) + io_lib:format("type ~p (i.e. ~s)", [O, opaque_type_to_iolist(N, S)]). + +opaque_type_to_iolist(N, {record, _}) -> + % N is the name of a record definition. + io_lib:format("record type ~p", [N]); +opaque_type_to_iolist(N, {variant, _}) -> + % N is the name of a variant definition. + io_lib:format("variant type ~p", [N]); +opaque_type_to_iolist(N, _) -> + % N is some other constructive type. + io_lib:format("type ~p", [N]). %%% AACI Getters