Skip to content

Commit a1b8d69

Browse files
Merge pull request #1891 from rabbitmq/fix-dialyzer-warnings-v3.7.x
Fix dialyzer warnings v3.7.x
2 parents cef66a3 + fd72f6e commit a1b8d69

27 files changed

+141
-124
lines changed

src/lager_exchange_backend.erl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@
3939
-record(state, {level :: {'mask', integer()},
4040
formatter :: atom(),
4141
format_config :: any(),
42-
init_exchange_ts = undefined :: rabbit_types:timestamp(),
43-
exchange = undefined :: #resource{}}).
42+
init_exchange_ts = undefined :: integer() | undefined,
43+
exchange = undefined :: #resource{} | undefined}).
4444

4545
-ifdef(TEST).
4646
-include_lib("eunit/include/eunit.hrl").
@@ -165,8 +165,8 @@ handle_log_event({log, Message},
165165
headers = Headers},
166166
Body = rabbit_data_coercion:to_binary(Formatter:format(Message, FormatConfig)),
167167
case rabbit_basic:publish(LogExch, RoutingKey, AmqpMsg, Body) of
168-
{ok, _DeliveredQPids} -> ok;
169-
{error, not_found} -> ok
168+
ok -> ok;
169+
{error, not_found} -> ok
170170
end,
171171
{ok, State};
172172
false ->

src/rabbit.erl

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -333,14 +333,10 @@ ensure_config() ->
333333
log_boot_error_and_exit(check_config_file, ErrFmt, ErrArgs)
334334
end,
335335
case rabbit_config:prepare_and_use_config() of
336-
{error, Reason} ->
337-
{Format, Arg} = case Reason of
338-
{generation_error, Error} -> {"~s", [Error]};
339-
Other -> {"~p", [Other]}
340-
end,
336+
{error, {generation_error, Error}} ->
341337
log_boot_error_and_exit(generate_config_file,
342-
"~nConfig file generation failed "++Format,
343-
Arg);
338+
"~nConfig file generation failed ~s",
339+
Error);
344340
ok -> ok
345341
end.
346342

@@ -683,6 +679,7 @@ stop_apps(Apps) ->
683679
end,
684680
ok.
685681

682+
-spec handle_app_error(_) -> fun((_, _) -> no_return()).
686683
handle_app_error(Term) ->
687684
fun(App, {bad_return, {_MFA, {'EXIT', ExitReason}}}) ->
688685
throw({Term, App, ExitReason});
@@ -972,6 +969,7 @@ boot_error(Class, Reason) ->
972969
[lager:pr_stacktrace(erlang:get_stacktrace(), {Class, Reason})] ++
973970
LogLocations).
974971

972+
-spec log_boot_error_and_exit(_, _, _) -> no_return().
975973
log_boot_error_and_exit(Reason, Format, Args) ->
976974
rabbit_log:error(Format, Args),
977975
io:format(standard_error, "~nBOOT FAILED~n===========~n" ++ Format ++ "~n", Args),

src/rabbit_amqqueue.erl

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@
8080
-spec declare
8181
(name(), boolean(), boolean(), rabbit_framing:amqp_table(),
8282
rabbit_types:maybe(pid()), rabbit_types:username()) ->
83-
{'new' | 'existing' | 'absent' | 'owner_died',
84-
rabbit_types:amqqueue()} |
83+
{'new' | 'existing' | 'owner_died', rabbit_types:amqqueue()} |
84+
{'absent', rabbit_types:amqqueue(), absent_reason()} |
8585
rabbit_types:channel_exit().
8686
-spec declare
8787
(name(), boolean(), boolean(), rabbit_framing:amqp_table(),
@@ -129,7 +129,7 @@
129129
-spec notify_policy_changed(rabbit_types:amqqueue()) -> 'ok'.
130130
-spec consumers(rabbit_types:amqqueue()) ->
131131
[{pid(), rabbit_types:ctag(), boolean(), non_neg_integer(),
132-
rabbit_framing:amqp_table()}].
132+
rabbit_framing:amqp_table(), binary()}].
133133
-spec consumer_info_keys() -> rabbit_types:info_keys().
134134
-spec consumers_all(rabbit_types:vhost()) ->
135135
[{name(), pid(), rabbit_types:ctag(), boolean(),
@@ -161,7 +161,7 @@
161161
-spec notify_down_all(qpids(), pid()) -> ok_or_errors().
162162
-spec notify_down_all(qpids(), pid(), non_neg_integer()) ->
163163
ok_or_errors().
164-
-spec activate_limit_all(qpids(), pid()) -> ok_or_errors().
164+
-spec activate_limit_all(qpids(), pid()) -> ok.
165165
-spec basic_get(rabbit_types:amqqueue(), pid(), boolean(), pid()) ->
166166
{'ok', non_neg_integer(), qmsg()} | 'empty'.
167167
-spec credit
@@ -453,6 +453,8 @@ not_found_or_absent(Name) ->
453453
[Q] -> {absent, Q, nodedown} %% Q exists on stopped node
454454
end.
455455

456+
-spec not_found_or_absent_dirty(name()) -> not_found_or_absent().
457+
456458
not_found_or_absent_dirty(Name) ->
457459
%% We should read from both tables inside a tx, to get a
458460
%% consistent view. But the chances of an inconsistency are small,
@@ -465,7 +467,7 @@ not_found_or_absent_dirty(Name) ->
465467
with(Name, F, E) ->
466468
with(Name, F, E, 2000).
467469

468-
with(Name, F, E, RetriesLeft) ->
470+
with(#resource{} = Name, F, E, RetriesLeft) ->
469471
case lookup(Name) of
470472
{ok, Q = #amqqueue{state = live}} when RetriesLeft =:= 0 ->
471473
%% Something bad happened to that queue, we are bailing out
@@ -527,9 +529,15 @@ retry_wait(Q = #amqqueue{pid = QPid, name = Name, state = QState}, F, E, Retries
527529
with(Name, F) -> with(Name, F, fun (E) -> {error, E} end).
528530

529531
with_or_die(Name, F) ->
530-
with(Name, F, fun (not_found) -> rabbit_misc:not_found(Name);
531-
({absent, Q, Reason}) -> rabbit_misc:absent(Q, Reason)
532-
end).
532+
with(Name, F, die_fun(Name)).
533+
534+
-spec die_fun(name()) ->
535+
fun((not_found_or_absent()) -> no_return()).
536+
537+
die_fun(Name) ->
538+
fun (not_found) -> rabbit_misc:not_found(Name);
539+
({absent, Q, Reason}) -> rabbit_misc:absent(Q, Reason)
540+
end.
533541

534542
assert_equivalence(#amqqueue{name = QName,
535543
durable = DurableQ,

src/rabbit_amqqueue_process.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ terminate_shutdown(Fun, #q{status = Status} = State) ->
355355
QName = qname(State),
356356
notify_decorators(shutdown, State),
357357
[emit_consumer_deleted(Ch, CTag, QName, ActingUser) ||
358-
{Ch, CTag, _, _, _} <-
358+
{Ch, CTag, _, _, _, _} <-
359359
rabbit_queue_consumers:all(Consumers)],
360360
State1#q{backing_queue_state = Fun(BQS)}
361361
end.

src/rabbit_basic.erl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
-type properties_input() ::
3030
rabbit_framing:amqp_property_record() | [{atom(), any()}].
3131
-type publish_result() ::
32-
{ok, [pid()]} | rabbit_types:error('not_found').
32+
ok | rabbit_types:error('not_found').
3333
-type header() :: any().
3434
-type headers() :: rabbit_framing:amqp_table() | 'undefined'.
3535

@@ -107,8 +107,8 @@ publish(Delivery = #delivery{
107107

108108
publish(X, Delivery) ->
109109
Qs = rabbit_amqqueue:lookup(rabbit_exchange:route(X, Delivery)),
110-
DeliveredQPids = rabbit_amqqueue:deliver(Qs, Delivery),
111-
{ok, DeliveredQPids}.
110+
_QPids = rabbit_amqqueue:deliver(Qs, Delivery),
111+
ok.
112112

113113
delivery(Mandatory, Confirm, Message, MsgSeqNo) ->
114114
#delivery{mandatory = Mandatory, confirm = Confirm, sender = self(),

src/rabbit_channel.erl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -773,9 +773,7 @@ send(Command, #ch{writer_pid = WriterPid}) ->
773773
ok = rabbit_writer:send_command(WriterPid, Command).
774774

775775
format_soft_error(#amqp_error{name = N, explanation = E, method = M}) ->
776-
io_lib:format("operation ~s caused a channel exception ~s: ~ts", [M, N, E]);
777-
format_soft_error(Reason) ->
778-
Reason.
776+
io_lib:format("operation ~s caused a channel exception ~s: ~ts", [M, N, E]).
779777

780778
handle_exception(Reason, State = #ch{protocol = Protocol,
781779
channel = Channel,

src/rabbit_config.erl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,7 @@ maybe_set_net_ticktime(KernelConfig) ->
121121
io:format(standard_error,
122122
"~nCouldn't set net_ticktime to ~p "
123123
"as net_kernel is busy changing net_ticktime to ~p seconds ~n",
124-
[NetTickTime, NewNetTicktime]);
125-
_ ->
126-
ok
124+
[NetTickTime, NewNetTicktime])
127125
end
128126
end.
129127

src/rabbit_health_check.erl

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,7 @@ run_checks([C|Cs]) ->
5353
node_health_check(list_channels) ->
5454
case rabbit_channel:info_local([pid]) of
5555
L when is_list(L) ->
56-
ok;
57-
Other ->
58-
ErrorMsg = io_lib:format("list_channels unexpected output: ~p",
59-
[Other]),
60-
{error_string, ErrorMsg}
56+
ok
6157
end;
6258

6359
node_health_check(list_queues) ->
@@ -66,11 +62,7 @@ node_health_check(list_queues) ->
6662
node_health_check(rabbit_node_monitor) ->
6763
case rabbit_node_monitor:partitions() of
6864
L when is_list(L) ->
69-
ok;
70-
Other ->
71-
ErrorMsg = io_lib:format("rabbit_node_monitor reports unexpected partitions value: ~p",
72-
[Other]),
73-
{error_string, ErrorMsg}
65+
ok
7466
end;
7567

7668
node_health_check(alarms) ->
@@ -87,9 +79,5 @@ health_check_queues([]) ->
8779
health_check_queues([VHost|RestVHosts]) ->
8880
case rabbit_amqqueue:info_local(VHost) of
8981
L when is_list(L) ->
90-
health_check_queues(RestVHosts);
91-
Other ->
92-
ErrorMsg = io_lib:format("list_queues unexpected output for vhost ~s: ~p",
93-
[VHost, Other]),
94-
{error_string, ErrorMsg}
82+
health_check_queues(RestVHosts)
9583
end.

src/rabbit_mirror_queue_master.erl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,18 @@
8181
%% Backing queue
8282
%% ---------------------------------------------------------------------------
8383

84+
-spec start(_, _) -> no_return().
8485
start(_Vhost, _DurableQueues) ->
8586
%% This will never get called as this module will never be
8687
%% installed as the default BQ implementation.
8788
exit({not_valid_for_generic_backing_queue, ?MODULE}).
8889

90+
-spec stop(_) -> no_return().
8991
stop(_Vhost) ->
9092
%% Same as start/1.
9193
exit({not_valid_for_generic_backing_queue, ?MODULE}).
9294

95+
-spec delete_crashed(_) -> no_return().
9396
delete_crashed(_QName) ->
9497
exit({not_valid_for_generic_backing_queue, ?MODULE}).
9598

@@ -223,6 +226,7 @@ purge(State = #state { gm = GM,
223226
{Count, BQS1} = BQ:purge(BQS),
224227
{Count, State #state { backing_queue_state = BQS1 }}.
225228

229+
-spec purge_acks(_) -> no_return().
226230
purge_acks(_State) -> exit({not_implemented, {?MODULE, purge_acks}}).
227231

228232
publish(Msg = #basic_message { id = MsgId }, MsgProps, IsDelivered, ChPid, Flow,

src/rabbit_mirror_queue_misc.erl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@
5858

5959
-spec remove_from_queue
6060
(rabbit_amqqueue:name(), pid(), [pid()]) ->
61-
{'ok', pid(), [pid()], [node()]} | {'error', 'not_found'}.
61+
{'ok', pid(), [pid()], [node()]} | {'error', 'not_found'} |
62+
{'error', {'not_synced', [pid()]}}.
6263
-spec add_mirrors(rabbit_amqqueue:name(), [node()], 'sync' | 'async') ->
6364
'ok'.
6465
-spec store_updated_slaves(rabbit_types:amqqueue()) ->

src/rabbit_mirror_queue_sync.erl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
non_neg_integer(),
6868
bq(), bqs()) ->
6969
{'already_synced', bqs()} | {'ok', bqs()} |
70+
{'cancelled', bqs()} |
7071
{'shutdown', any(), bqs()} |
7172
{'sync_died', any(), bqs()}.
7273
-spec slave(non_neg_integer(), reference(), timer:tref(), pid(),

src/rabbit_mnesia.erl

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -163,20 +163,14 @@ init_from_config() ->
163163
{DiscoveredNodes, NodeType} =
164164
case rabbit_peer_discovery:discover_cluster_nodes() of
165165
{ok, {Nodes, Type} = Config}
166-
when is_list(Nodes) andalso (Type == disc orelse Type == disk orelse Type == ram) ->
166+
when is_list(Nodes) andalso
167+
(Type == disc orelse Type == disk orelse Type == ram) ->
167168
case lists:foldr(FindBadNodeNames, [], Nodes) of
168169
[] -> Config;
169170
BadNames -> e({invalid_cluster_node_names, BadNames})
170171
end;
171172
{ok, {_, BadType}} when BadType /= disc andalso BadType /= ram ->
172173
e({invalid_cluster_node_type, BadType});
173-
{ok, Nodes} when is_list(Nodes) ->
174-
%% The legacy syntax (a nodes list without the node
175-
%% type) is unsupported.
176-
case lists:foldr(FindBadNodeNames, [], Nodes) of
177-
[] -> e(cluster_node_type_mandatory);
178-
_ -> e(invalid_cluster_nodes_conf)
179-
end;
180174
{ok, _} ->
181175
e(invalid_cluster_nodes_conf)
182176
end,
@@ -978,6 +972,8 @@ nodes_incl_me(Nodes) -> lists:usort([node()|Nodes]).
978972

979973
nodes_excl_me(Nodes) -> Nodes -- [node()].
980974

975+
-spec e(any()) -> no_return().
976+
981977
e(Tag) -> throw({error, {Tag, error_description(Tag)}}).
982978

983979
error_description({invalid_cluster_node_names, BadNames}) ->
@@ -987,9 +983,6 @@ error_description({invalid_cluster_node_type, BadType}) ->
987983
"In the 'cluster_nodes' configuration key, the node type is invalid "
988984
"(expected 'disc' or 'ram'): " ++
989985
lists:flatten(io_lib:format("~p", [BadType]));
990-
error_description(cluster_node_type_mandatory) ->
991-
"The 'cluster_nodes' configuration key must indicate the node type: "
992-
"either {[...], disc} or {[...], ram}";
993986
error_description(invalid_cluster_nodes_conf) ->
994987
"The 'cluster_nodes' configuration key is invalid, it must be of the "
995988
"form {[Nodes], Type}, where Nodes is a list of node names and "

src/rabbit_networking.erl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
-spec tcp_listener_addresses(listener_config()) -> [address()].
9494
-spec tcp_listener_spec
9595
(name_prefix(), address(), [gen_tcp:listen_option()], module(), module(),
96-
protocol(), any(), non_neg_integer(), label()) ->
96+
any(), protocol(), non_neg_integer(), label()) ->
9797
supervisor:child_spec().
9898
-spec ensure_ssl() -> rabbit_types:infos().
9999
-spec poodle_check(atom()) -> 'ok' | 'danger'.
@@ -113,6 +113,11 @@
113113
_) ->
114114
'ok'.
115115

116+
%% @todo Remove once Dialyzer only runs on Erlang/OTP 21.3 or above.
117+
-dialyzer({nowarn_function, boot/0}).
118+
-dialyzer({nowarn_function, boot_listeners/3}).
119+
-dialyzer({nowarn_function, record_distribution_listener/0}).
120+
116121
%%----------------------------------------------------------------------------
117122

118123
boot() ->
@@ -427,6 +432,7 @@ gethostaddr(Host, Family) ->
427432
{error, Reason} -> host_lookup_error(Host, Reason)
428433
end.
429434

435+
-spec host_lookup_error(_, _) -> no_return().
430436
host_lookup_error(Host, Reason) ->
431437
rabbit_log:error("invalid host ~p - ~p~n", [Host, Reason]),
432438
throw({error, {invalid_host, Host, Reason}}).

src/rabbit_node_monitor.erl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,9 @@ cluster_status_filename() ->
104104

105105
prepare_cluster_status_files() ->
106106
rabbit_mnesia:ensure_mnesia_dir(),
107-
Corrupt = fun(F) -> throw({error, corrupt_cluster_status_files, F}) end,
108107
RunningNodes1 = case try_read_file(running_nodes_filename()) of
109108
{ok, [Nodes]} when is_list(Nodes) -> Nodes;
110-
{ok, Other} -> Corrupt(Other);
109+
{ok, Other} -> corrupt_cluster_status_files(Other);
111110
{error, enoent} -> []
112111
end,
113112
ThisNode = [node()],
@@ -121,14 +120,19 @@ prepare_cluster_status_files() ->
121120
{ok, [AllNodes0]} when is_list(AllNodes0) ->
122121
{legacy_cluster_nodes(AllNodes0), legacy_disc_nodes(AllNodes0)};
123122
{ok, Files} ->
124-
Corrupt(Files);
123+
corrupt_cluster_status_files(Files);
125124
{error, enoent} ->
126125
LegacyNodes = legacy_cluster_nodes([]),
127126
{LegacyNodes, LegacyNodes}
128127
end,
129128
AllNodes2 = lists:usort(AllNodes1 ++ RunningNodes2),
130129
ok = write_cluster_status({AllNodes2, DiscNodes, RunningNodes2}).
131130

131+
-spec corrupt_cluster_status_files(any()) -> no_return().
132+
133+
corrupt_cluster_status_files(F) ->
134+
throw({error, corrupt_cluster_status_files, F}).
135+
132136
write_cluster_status({All, Disc, Running}) ->
133137
ClusterStatusFN = cluster_status_filename(),
134138
Res = case rabbit_file:write_term_file(ClusterStatusFN, [{All, Disc}]) of

0 commit comments

Comments
 (0)