Skip to content

Commit b4f7adb

Browse files
the-mikedavisdcorbacho
authored andcommitted
Fix dialyzer errors in rabbit application
This commit has three fixes that make the dialyzer tests pass for the rabbit app: * 'pick_node_in_cluster/1' is only called by a function which asserts that the cluster list is non-empty, so the assertion could never fail. I've replaced the assertion with an equivalent pattern match in the function head. * 'get_sys_status/1' will fail in its call to 'sys:get_status/1' according to the typespec but not in practice when passed a Ra server ID ('ra:server_id()' type). I added no-warn attributes to suppress those warnings. * 'check_cluster_consistency/0' would throw its error but the caller could handle and bubble-up the error tuple. I have changed it to return the error tuple.
1 parent b51a6f8 commit b4f7adb

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

deps/rabbit/src/rabbit_khepri.erl

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@
9494

9595
-compile({no_auto_import, [get/1, get/2, nodes/0]}).
9696

97+
%% `sys:get_status/1''s spec only allows `sys:name()' but can work on any
98+
%% `erlang:send_destination()' including a `ra:server_id()'.
99+
-dialyzer({nowarn_function, get_sys_status/1}).
100+
-dialyzer({no_match, [status/0, cluster_status_from_khepri/0]}).
101+
97102
-define(RA_SYSTEM, coordination).
98103
-define(RA_CLUSTER_NAME, metadata_store).
99104
-define(RA_FRIENDLY_NAME, "RabbitMQ metadata store").
@@ -157,8 +162,7 @@ add_member(JoiningNode, [_ | _] = Cluster) ->
157162
{ok, already_member}
158163
end.
159164

160-
pick_node_in_cluster(Cluster) when is_list(Cluster) ->
161-
?assertNotEqual([], Cluster),
165+
pick_node_in_cluster([_ | _] = Cluster) when is_list(Cluster) ->
162166
ThisNode = node(),
163167
case lists:member(ThisNode, Cluster) of
164168
true -> ThisNode;
@@ -404,6 +408,7 @@ status() ->
404408
end
405409
end || N <- Nodes].
406410

411+
407412
get_sys_status(Proc) ->
408413
try lists:nth(5, element(4, sys:get_status(Proc))) of
409414
Sys -> {ok, Sys}
@@ -540,7 +545,7 @@ check_cluster_consistency() ->
540545
{error, not_found} ->
541546
ok;
542547
{error, _} = E ->
543-
throw(E)
548+
E
544549
end.
545550

546551
nodes_excl_me(Nodes) -> Nodes -- [node()].

0 commit comments

Comments
 (0)