Skip to content

Commit

Permalink
Merge pull request #6544 from rabbitmq/rin/dialyzer-fixes
Browse files Browse the repository at this point in the history
Fix rabbit_misc:hexify/1 when called with a list
  • Loading branch information
michaelklishin committed Dec 2, 2022
2 parents e4c88a3 + cf3fa10 commit a3344e2
Show file tree
Hide file tree
Showing 35 changed files with 75 additions and 91 deletions.
1 change: 0 additions & 1 deletion deps/rabbit_common/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ plt(

dialyze(
plt = ":base_plt",
warnings_as_errors = False,
)

suites = [
Expand Down
2 changes: 1 addition & 1 deletion deps/rabbit_common/src/rabbit_core_metrics.erl
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ auth_attempt_failed(RemoteAddress, Username, Protocol) ->
update_auth_attempt(RemoteAddress, Username, Protocol, Incr) ->
%% It should default to false as per ip/user metrics could keep growing indefinitely
%% It's up to the operator to enable them, and reset it required
case application:get_env(rabbit, track_auth_attempt_source) of
_ = case application:get_env(rabbit, track_auth_attempt_source) of
{ok, true} ->
case {RemoteAddress, Username} of
{<<>>, <<>>} ->
Expand Down
2 changes: 1 addition & 1 deletion deps/rabbit_common/src/rabbit_data_coercion.erl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
-export([to_atom/2, atomize_keys/1, to_list_of_binaries/1]).
-export([to_utf8_binary/1, to_unicode_charlist/1]).

-spec to_binary(Val :: binary() | list() | atom() | integer()) -> binary().
-spec to_binary(Val :: binary() | list() | atom() | integer() | function()) -> binary().
to_binary(Val) when is_list(Val) -> list_to_binary(Val);
to_binary(Val) when is_atom(Val) -> atom_to_binary(Val, utf8);
to_binary(Val) when is_integer(Val) -> integer_to_binary(Val);
Expand Down
2 changes: 1 addition & 1 deletion deps/rabbit_common/src/rabbit_date_time.erl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ is_in_the_past({_Y, _M, _D} = Date) ->

DateInDays < TodayInDays.

-spec parse_duration(string()) -> datetime_plist().
-spec parse_duration(string()) -> {ok, datetime_plist()} | error.
parse_duration(Bin)
when is_binary(Bin) -> %TODO extended format
parse_duration(binary_to_list(Bin));
Expand Down
2 changes: 1 addition & 1 deletion deps/rabbit_common/src/rabbit_env.erl
Original file line number Diff line number Diff line change
Expand Up @@ -2114,7 +2114,7 @@ is_rabbitmq_loaded_on_remote_node(

maybe_stop_dist_for_remote_query(
#{dist_started_for_remote_query := true} = Context) ->
net_kernel:stop(),
_ = net_kernel:stop(),
maps:remove(dist_started_for_remote_query, Context);
maybe_stop_dist_for_remote_query(Context) ->
Context.
Expand Down
10 changes: 6 additions & 4 deletions deps/rabbit_common/src/rabbit_json.erl
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,20 @@ try_decode(JSON, Opts) ->
{error, Reason}
end.

-spec encode(thoas:json_term()) -> iodata().
-spec encode(thoas:input_term()) -> iodata().
encode(Term) ->
encode(Term, ?DEFAULT_ENCODE_OPTIONS).

-spec encode(thoas:json_term(), thoas:encode_options()) -> iodata().
-spec encode(thoas:input_term(), thoas:encode_options()) -> iodata().
encode(Term, Opts) ->
%% Fixup for JSON encoding
%% * Transforms any Funs into strings
%% See rabbit_mgmt_format:format_nulls/1
F = fun(V) when is_function(V) ->
F = fun
(V) when is_function(V) ->
rabbit_data_coercion:to_binary(V);
(V) -> V
(V) ->
V
end,
thoas:encode(fixup_terms(Term, F), Opts).

Expand Down
2 changes: 1 addition & 1 deletion deps/rabbit_common/src/rabbit_misc.erl
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ pid_to_string(Pid) when is_pid(Pid) ->
hexify(Bin) when is_binary(Bin) ->
iolist_to_binary([io_lib:format("~2.16.0B", [V]) || <<V:8>> <= Bin]);
hexify(Bin) when is_list(Bin) ->
hexify(erlang:binary_to_list(Bin));
hexify(erlang:list_to_binary(Bin));
hexify(Bin) when is_atom(Bin) ->
hexify(erlang:atom_to_binary(Bin)).

Expand Down
2 changes: 1 addition & 1 deletion deps/rabbit_common/src/rabbit_writer.erl
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ internal_send_command_async(MethodRecord, Content,
writer_gc_threshold = GCThreshold}) ->
Frames = assemble_frames(Channel, MethodRecord, Content, FrameMax,
Protocol),
maybe_gc_large_msg(Content, GCThreshold),
_ = maybe_gc_large_msg(Content, GCThreshold),
maybe_flush(State#wstate{pending = [Frames | Pending]}).

%% When the amount of protocol method data buffered exceeds
Expand Down
9 changes: 8 additions & 1 deletion deps/rabbit_common/test/unit_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ groups() ->
frame_encoding_does_not_fail_with_empty_binary_payload,
amqp_table_conversion,
name_type,
get_erl_path
get_erl_path,
hexify
]},
{parse_mem_limit, [parallel], [
parse_mem_limit_relative_exactly_max,
Expand Down Expand Up @@ -466,6 +467,12 @@ get_erl_path(_) ->
end,
ok.

hexify(_) ->
?assertEqual(<<"68656C6C6F">>, rabbit_misc:hexify(<<"hello">>)),
?assertEqual(<<"68656C6C6F">>, rabbit_misc:hexify("hello")),
?assertEqual(<<"68656C6C6F">>, rabbit_misc:hexify(hello)),
ok.

date_time_parse_duration(_) ->
?assertEqual(
{ok, [{sign, "+"}, {years, 6}, {months, 3}, {days, 1}, {hours, 1}, {minutes, 1}, {seconds, 1}]},
Expand Down
1 change: 0 additions & 1 deletion deps/rabbitmq_auth_backend_cache/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ plt(
dialyze(
dialyzer_opts = RABBITMQ_DIALYZER_OPTS,
plt = ":base_plt",
warnings_as_errors = False,
)

broker_for_integration_suites()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ init([]) ->

{ok, AuthCacheArgs} = application:get_env(rabbitmq_auth_backend_cache, cache_module_args),
% Load module to be able to check exported function.
code:load_file(AuthCache),
_ = code:load_file(AuthCache),
ChildSpecs = case erlang:function_exported(AuthCache, start_link,
length(AuthCacheArgs)) of
true -> [{auth_cache, {AuthCache, start_link, AuthCacheArgs},
Expand Down
13 changes: 0 additions & 13 deletions deps/rabbitmq_auth_backend_cache/src/rabbit_auth_cache.erl
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,12 @@

-export([expiration/1, expired/1]).

-ifdef(use_specs).

-callback get(term()) -> term().

-callback put(term(), term(), integer()) -> ok.

-callback delete(term()) -> ok.

-else.

-export([behaviour_info/1]).

behaviour_info(callbacks) ->
[{get, 1}, {put, 3}, {delete, 1}];
behaviour_info(_Other) ->
undefined.

-endif.

expiration(TTL) ->
erlang:system_time(milli_seconds) + TTL.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ do_delete(Key) ->
erase({items, Key}),
case erlang:get({timers, Key}) of
undefined -> ok;
Tref -> timer:cancel(Tref),
Tref -> _ = timer:cancel(Tref),
erase({timers, Key})

end.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ terminate(_Reason, State = #state{}) ->
do_delete(Key, Table, Timers) ->
true = ets:delete(Table, Key),
case ets:lookup(Timers, Key) of
[{Key, Tref}] -> timer:cancel(Tref),
[{Key, Tref}] -> _ = timer:cancel(Tref),
true = ets:delete(Timers, Key);
[] -> ok
end.
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ put(Key, Value, TTL) ->
ok.

delete(Key) ->
[ets:delete(Table, Key)
|| Table <- gen_server:call(?MODULE, get_segment_tables, ?CACHE_OPERATION_TIMEOUT)].
_ = [ets:delete(Table, Key)
|| Table <- gen_server:call(?MODULE, get_segment_tables, ?CACHE_OPERATION_TIMEOUT)],
ok.

gc() ->
case whereis(?MODULE) of
Expand Down Expand Up @@ -79,7 +80,7 @@ code_change(_OldVsn, State, _Extra) ->
{ok, State}.

terminate(_Reason, State = #state{gc_timer = Timer}) ->
timer:cancel(Timer),
_ = timer:cancel(Timer),
State.

partition_expired_segments(Segments) ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ put(Key, Value, TTL) ->
ok.

delete(Key) ->
[ets:delete(Table, Key)
|| Table <- get_all_segment_tables()].
_ = [ets:delete(Table, Key)
|| Table <- get_all_segment_tables()],
ok.

gc() ->
case whereis(?MODULE) of
Expand All @@ -53,7 +54,7 @@ gc() ->
end.

init([SegmentSize]) ->
ets:new(?SEGMENT_TABLE, [ordered_set, named_table, public]),
_ = ets:new(?SEGMENT_TABLE, [ordered_set, named_table, public]),
ets:insert(?SEGMENT_TABLE, {segment_size, SegmentSize}),

InitSegment = segment(rabbit_auth_cache:expiration(SegmentSize), SegmentSize),
Expand Down Expand Up @@ -83,7 +84,7 @@ code_change(_OldVsn, State, _Extra) ->
{ok, State}.

terminate(_Reason, State = #state{gc_timer = Timer}) ->
timer:cancel(Timer),
_ = timer:cancel(Timer),
State.

segment(Expiration, SegmentSize) ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,7 @@ do_http_req(Path0, Query) ->
{ok, {{_HTTP, Code, _}, _Headers, Body}} ->
rabbit_log:debug("auth_backend_http: response code is ~tp, body: ~tp", [Code, Body]),
case lists:member(Code, ?SUCCESSFUL_RESPONSE_CODES) of
true -> case parse_resp(Body) of
{error, _} = E -> E;
Resp -> Resp
end;
true -> parse_resp(Body);
false -> {error, {Code, Body}}
end;
{error, _} = E ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ get_or_create_conn(IsAnon, Servers, Opts) ->
{ok, Conn} ->
Timeout = rabbit_misc:pget(idle_timeout, Opts, infinity),
%% Defer the timeout by re-setting it.
set_connection_timeout(Key, Timeout),
_ = set_connection_timeout(Key, Timeout),
{ok, {eldap_pooled, Conn}};
error ->
{Timeout, EldapOpts} = case lists:keytake(idle_timeout, 1, Opts) of
Expand All @@ -645,7 +645,7 @@ get_or_create_conn(IsAnon, Servers, Opts) ->
%% Non-zero timeout, put it in the pool
{{ok, Conn}, Timeout} ->
put(ldap_conns, maps:put(Key, Conn, Conns)),
set_connection_timeout(Key, Timeout),
_ = set_connection_timeout(Key, Timeout),
{ok, {eldap_pooled, Conn}};
{Error, _} ->
Error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ start(_Type, _StartArgs) ->
{ok, TLS} = application:get_env(rabbitmq_auth_backend_ldap, use_starttls),
case SSL orelse TLS of
true ->
rabbit_networking:ensure_ssl(),
_ = rabbit_networking:ensure_ssl(),
ok;
false -> ok
end,
Expand Down
18 changes: 9 additions & 9 deletions deps/rabbitmq_ct_client_helpers/src/rabbit_ct_client_helpers.erl
Original file line number Diff line number Diff line change
Expand Up @@ -253,12 +253,12 @@ close_channels_and_connection(Config, Node) ->
end.

publish(Ch, QName, Count) ->
amqp_channel:call(Ch, #'confirm.select'{}),
[amqp_channel:call(Ch,
#'basic.publish'{routing_key = QName},
#amqp_msg{props = #'P_basic'{delivery_mode = 2},
payload = list_to_binary(integer_to_list(I))})
|| I <- lists:seq(1, Count)],
_ = amqp_channel:call(Ch, #'confirm.select'{}),
_ = [amqp_channel:call(Ch,
#'basic.publish'{routing_key = QName},
#amqp_msg{props = #'P_basic'{delivery_mode = 2},
payload = list_to_binary(integer_to_list(I))})
|| I <- lists:seq(1, Count)],
amqp_channel:wait_for_confirms(Ch).

consume(Ch, QName, Count) ->
Expand Down Expand Up @@ -296,7 +296,7 @@ accumulate_without_acknowledging(Ch, CTag, Remaining, Acc) ->


fetch(Ch, QName, Count) ->
[{#'basic.get_ok'{}, _} =
amqp_channel:call(Ch, #'basic.get'{queue = QName}) ||
_ <- lists:seq(1, Count)],
_ = [{#'basic.get_ok'{}, _} =
amqp_channel:call(Ch, #'basic.get'{queue = QName}) ||
_ <- lists:seq(1, Count)],
ok.
1 change: 0 additions & 1 deletion deps/rabbitmq_event_exchange/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ plt(
dialyze(
dialyzer_opts = RABBITMQ_DIALYZER_OPTS,
plt = ":base_plt",
warnings_as_errors = False,
)

broker_for_integration_suites()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ info(_X) -> [].
info(_X, _) -> [].

register() ->
rabbit_exchange:declare(exchange(), topic, true, false, true, [],
?INTERNAL_USER),
_ = rabbit_exchange:declare(exchange(), topic, true, false, true, [],
?INTERNAL_USER),
gen_event:add_handler(rabbit_event, ?MODULE, []).

unregister() ->
rabbit_exchange:delete(exchange(), false, ?INTERNAL_USER),
_ = rabbit_exchange:delete(exchange(), false, ?INTERNAL_USER),
gen_event:delete_handler(rabbit_event, ?MODULE, []).

exchange() ->
Expand Down Expand Up @@ -73,7 +73,7 @@ handle_event(#event{type = Type,
props = Props,
timestamp = TS,
reference = none}, #state{vhost = VHost} = State) ->
case key(Type) of
_ = case key(Type) of
ignore -> ok;
Key ->
Props2 = [{<<"timestamp_in_ms">>, TS} | Props],
Expand Down
1 change: 0 additions & 1 deletion deps/rabbitmq_peer_discovery_common/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ plt(
dialyze(
dialyzer_opts = RABBITMQ_DIALYZER_OPTS,
plt = ":base_plt",
warnings_as_errors = False,
)

broker_for_integration_suites()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,8 @@ maybe_configure_proxy() ->
"Configured HTTP proxy: ~tp, HTTPS proxy: ~tp, exclusions: ~tp",
[HttpProxy, HttpsProxy, ProxyExclusions],
#{domain => ?RMQLOG_DOMAIN_PEER_DIS}),
maybe_set_proxy(proxy, HttpProxy, ProxyExclusions),
maybe_set_proxy(https_proxy, HttpsProxy, ProxyExclusions),
_ = maybe_set_proxy(proxy, HttpProxy, ProxyExclusions),
_ = maybe_set_proxy(https_proxy, HttpsProxy, ProxyExclusions),
ok
end.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ node_prefix() ->
case getenv("RABBITMQ_NODENAME") of
false -> ?DEFAULT_NODE_PREFIX;
Value ->
rabbit_data_coercion:to_list(getenv("RABBITMQ_NODENAME")),
_ = rabbit_data_coercion:to_list(getenv("RABBITMQ_NODENAME")),
lists:nth(1, string:tokens(Value, "@"))
end.

Expand Down
1 change: 0 additions & 1 deletion deps/rabbitmq_tracing/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ plt(
dialyze(
dialyzer_opts = RABBITMQ_DIALYZER_OPTS,
plt = ":base_plt",
warnings_as_errors = False,
)

broker_for_integration_suites()
Expand Down
6 changes: 3 additions & 3 deletions deps/rabbitmq_tracing/src/rabbit_tracing_consumer.erl
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ handle_info(_I, State) ->

terminate(shutdown, State = #state{conn = Conn, ch = Ch,
file = F, filename = Filename}) ->
flush(State),
_ = flush(State),
catch amqp_channel:close(Ch),
catch amqp_connection:close(Conn),
catch prim_file:close(F),
Expand Down Expand Up @@ -196,7 +196,7 @@ log(text, Record, State) ->
print_log(io_lib:format(Fmt, Args), State);

log(json, Record, State) ->
print_log([rabbit_json:encode(
_ = print_log([rabbit_json:encode(
#{timestamp => Record#log_record.timestamp,
type => Record#log_record.type,
node => Record#log_record.node,
Expand All @@ -223,7 +223,7 @@ maybe_flush(State) ->
State.

flush(State = #state{file = F, buf = Buf}) ->
prim_file:write(F, lists:reverse(Buf)),
_ = prim_file:write(F, lists:reverse(Buf)),
State#state{buf = [], buf_cnt = 0}.

truncate(Payload, #state{max_payload = Max}) ->
Expand Down
4 changes: 2 additions & 2 deletions deps/rabbitmq_tracing/src/rabbit_tracing_sup.erl
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ start_child(Id, Args) ->
[rabbit_tracing_consumer_sup]}).

stop_child(Id) ->
supervisor:terminate_child(?SUPERVISOR, Id),
supervisor:delete_child(?SUPERVISOR, Id),
_ = supervisor:terminate_child(?SUPERVISOR, Id),
_ = supervisor:delete_child(?SUPERVISOR, Id),
ok.

%%----------------------------------------------------------------------------
Expand Down
Loading

0 comments on commit a3344e2

Please sign in to comment.