From 0e5207fec1e544fb41a97c1951192c4892186f10 Mon Sep 17 00:00:00 2001 From: Johannes Christ Date: Sun, 11 Jun 2023 21:53:02 +0200 Subject: [PATCH] Fix some complaints by dialyzer on returns Not all warnings were fixed as Elixir's `is_nil` in conditions does not seem to play well with dialyzer. --- lib/mix/tasks/gh/docs.ex | 1 + lib/nostrum/api.ex | 2 +- lib/nostrum/cache/channel_guild_mapping/ets.ex | 2 +- lib/nostrum/cache/guild_cache/ets.ex | 2 +- lib/nostrum/cache/member_cache/ets.ex | 2 +- lib/nostrum/cache/presence_cache/ets.ex | 2 +- lib/nostrum/cache/user_cache/ets.ex | 2 +- lib/nostrum/consumer.ex | 7 ++++--- lib/nostrum/shard/dispatch.ex | 6 +++--- lib/nostrum/store/guild_shard_mapping/ets.ex | 2 +- lib/nostrum/store/unavailable_guild/ets.ex | 2 +- lib/nostrum/voice.ex | 6 +++--- lib/nostrum/voice/audio.ex | 4 ++-- lib/nostrum/voice/ports.ex | 4 +++- lib/nostrum/voice/session.ex | 2 +- lib/nostrum/voice/supervisor.ex | 2 +- 16 files changed, 26 insertions(+), 22 deletions(-) diff --git a/lib/mix/tasks/gh/docs.ex b/lib/mix/tasks/gh/docs.ex index 3ac5cd154..efdba2cb1 100644 --- a/lib/mix/tasks/gh/docs.ex +++ b/lib/mix/tasks/gh/docs.ex @@ -17,6 +17,7 @@ defmodule Mix.Tasks.Gh.Docs do # Taken from https://gist.github.com/jjh42/5737777 with some modifications @shortdoc "Mix task to publish gh-pages site." + @dialyzer {:nowarn_function, run: 1} def run(_) do File.rm_rf("doc") Mix.Task.run("docs") diff --git a/lib/nostrum/api.ex b/lib/nostrum/api.ex index 78ddff59c..6fee61181 100644 --- a/lib/nostrum/api.ex +++ b/lib/nostrum/api.ex @@ -179,7 +179,7 @@ defmodule Nostrum.Api do """ @spec update_status(status, String.t(), integer, String.t() | nil) :: :ok def update_status(status, game, type \\ 0, stream \\ nil) do - Supervisor.update_status(to_string(status), game, stream, type) + _result = Supervisor.update_status(to_string(status), game, stream, type) :ok end diff --git a/lib/nostrum/cache/channel_guild_mapping/ets.ex b/lib/nostrum/cache/channel_guild_mapping/ets.ex index 1b08bbd53..ff250cf7c 100644 --- a/lib/nostrum/cache/channel_guild_mapping/ets.ex +++ b/lib/nostrum/cache/channel_guild_mapping/ets.ex @@ -24,7 +24,7 @@ defmodule Nostrum.Cache.ChannelGuildMapping.ETS do @doc "Set up the ETS table." @impl Supervisor def init(_init_arg) do - :ets.new(@table_name, [:set, :public, :named_table]) + _tid = :ets.new(@table_name, [:set, :public, :named_table]) Supervisor.init([], strategy: :one_for_one) end diff --git a/lib/nostrum/cache/guild_cache/ets.ex b/lib/nostrum/cache/guild_cache/ets.ex index 62c11d55f..fc94b9b46 100644 --- a/lib/nostrum/cache/guild_cache/ets.ex +++ b/lib/nostrum/cache/guild_cache/ets.ex @@ -36,7 +36,7 @@ defmodule Nostrum.Cache.GuildCache.ETS do @doc "Set up the cache's ETS table." @impl Supervisor def init(_init_arg) do - :ets.new(tabname(), [:set, :public, :named_table]) + _tid = :ets.new(tabname(), [:set, :public, :named_table]) Supervisor.init([], strategy: :one_for_one) end diff --git a/lib/nostrum/cache/member_cache/ets.ex b/lib/nostrum/cache/member_cache/ets.ex index 557d06cf8..4cd096d2e 100644 --- a/lib/nostrum/cache/member_cache/ets.ex +++ b/lib/nostrum/cache/member_cache/ets.ex @@ -25,7 +25,7 @@ defmodule Nostrum.Cache.MemberCache.ETS do @doc "Set up the cache's ETS table." @impl Supervisor def init(_init_arg) do - :ets.new(@table_name, [:set, :public, :named_table]) + _tid = :ets.new(@table_name, [:set, :public, :named_table]) Supervisor.init([], strategy: :one_for_one) end diff --git a/lib/nostrum/cache/presence_cache/ets.ex b/lib/nostrum/cache/presence_cache/ets.ex index 49cdc9bba..a5a6b2276 100644 --- a/lib/nostrum/cache/presence_cache/ets.ex +++ b/lib/nostrum/cache/presence_cache/ets.ex @@ -30,7 +30,7 @@ defmodule Nostrum.Cache.PresenceCache.ETS do @doc "Set up the cache's ETS table." @impl Supervisor def init(_init_arg) do - :ets.new(@table_name, [:set, :public, :named_table]) + _tid = :ets.new(@table_name, [:set, :public, :named_table]) Supervisor.init([], strategy: :one_for_one) end diff --git a/lib/nostrum/cache/user_cache/ets.ex b/lib/nostrum/cache/user_cache/ets.ex index 92cfdc20c..ad66ae217 100644 --- a/lib/nostrum/cache/user_cache/ets.ex +++ b/lib/nostrum/cache/user_cache/ets.ex @@ -22,7 +22,7 @@ defmodule Nostrum.Cache.UserCache.ETS do @doc "Set up the ETS table." @impl Supervisor def init(_init_arg) do - :ets.new(@table_name, [:set, :public, :named_table]) + _tid = :ets.new(@table_name, [:set, :public, :named_table]) Supervisor.init([], strategy: :one_for_one) end diff --git a/lib/nostrum/consumer.ex b/lib/nostrum/consumer.ex index 5de0bfb5e..2292ecc3e 100644 --- a/lib/nostrum/consumer.ex +++ b/lib/nostrum/consumer.ex @@ -433,9 +433,10 @@ defmodule Nostrum.Consumer do @impl GenServer def handle_info({:event, event}, state) do - Task.start_link(fn -> - __MODULE__.handle_event(event) - end) + {:ok, _pid} = + Task.start_link(fn -> + __MODULE__.handle_event(event) + end) {:noreply, state} end diff --git a/lib/nostrum/shard/dispatch.ex b/lib/nostrum/shard/dispatch.ex index 56656f836..c1ae579a1 100644 --- a/lib/nostrum/shard/dispatch.ex +++ b/lib/nostrum/shard/dispatch.ex @@ -180,7 +180,7 @@ defmodule Nostrum.Shard.Dispatch do def handle_event(:GUILD_MEMBER_ADD = event, p, state) do GuildCache.member_count_up(p.guild_id) - UserCache.create(p.user) + _new_user = UserCache.create(p.user) {event, {p.guild_id, MemberCache.create(p.guild_id, p)}, state} end @@ -326,7 +326,7 @@ defmodule Nostrum.Shard.Dispatch do voice = Voice.get_voice(p.guild_id) if voice.persist_playback, - do: Voice.resume(p.guild_id) + do: _result = Voice.resume(p.guild_id) {event, VoiceReady.to_struct(p), state} end @@ -367,7 +367,7 @@ defmodule Nostrum.Shard.Dispatch do end end - GuildCache.voice_state_update(p.guild_id, p) + {_updated, _states} = GuildCache.voice_state_update(p.guild_id, p) {event, VoiceState.to_struct(p), state} end diff --git a/lib/nostrum/store/guild_shard_mapping/ets.ex b/lib/nostrum/store/guild_shard_mapping/ets.ex index e59d7bde6..95ac0f0a1 100644 --- a/lib/nostrum/store/guild_shard_mapping/ets.ex +++ b/lib/nostrum/store/guild_shard_mapping/ets.ex @@ -33,7 +33,7 @@ defmodule Nostrum.Store.GuildShardMapping.ETS do @doc "Set up the store's ETS table." @impl Supervisor def init(_init_arg) do - :ets.new(@table_name, [:set, :public, :named_table]) + _tid = :ets.new(@table_name, [:set, :public, :named_table]) Supervisor.init([], strategy: :one_for_one) end diff --git a/lib/nostrum/store/unavailable_guild/ets.ex b/lib/nostrum/store/unavailable_guild/ets.ex index 0aba6844c..b10ab1260 100644 --- a/lib/nostrum/store/unavailable_guild/ets.ex +++ b/lib/nostrum/store/unavailable_guild/ets.ex @@ -31,7 +31,7 @@ defmodule Nostrum.Store.UnavailableGuild.ETS do @impl Supervisor @doc "Set up the store's ETS table." def init(_init_arg) do - :ets.new(@table_name, [:set, :public, :named_table]) + _tid = :ets.new(@table_name, [:set, :public, :named_table]) Supervisor.init([], strategy: :one_for_one) end diff --git a/lib/nostrum/voice.ex b/lib/nostrum/voice.ex index 679e13a45..58ba05cf2 100644 --- a/lib/nostrum/voice.ex +++ b/lib/nostrum/voice.ex @@ -553,7 +553,7 @@ defmodule Nostrum.Voice do voice = get_voice(guild_id) if VoiceState.ready_for_rtp?(voice) do - Audio.send_frames(frames, voice) + {_, _sent_all?} = Audio.send_frames(frames, voice) :ok else {:error, "Must be connected to voice channel to send frames."} @@ -573,7 +573,7 @@ defmodule Nostrum.Voice do cond do VoiceState.ready_for_ws?(voice) -> - VoiceSupervisor.create_session(voice) + {:ok, _pid} = VoiceSupervisor.create_session(voice) :ok is_nil(voice) -> @@ -753,7 +753,7 @@ defmodule Nostrum.Voice do state = Map.put(state, guild_id, voice) if Application.get_env(:nostrum, :voice_auto_connect, true), - do: start_if_ready(voice) + do: _result = start_if_ready(voice) {:reply, voice, state} end diff --git a/lib/nostrum/voice/audio.ex b/lib/nostrum/voice/audio.ex index ab43b147a..5cb246134 100644 --- a/lib/nostrum/voice/audio.ex +++ b/lib/nostrum/voice/audio.ex @@ -124,7 +124,7 @@ defmodule Nostrum.Voice.Audio do |> Enum.take(frames_per_burst()) |> send_frames(voice) - :timer.cancel(watchdog) + {:ok, :cancel} = :timer.cancel(watchdog) if done, do: on_complete(voice, init?), @@ -136,7 +136,7 @@ defmodule Nostrum.Voice.Audio do def send_frames(frames, %VoiceState{} = voice) do voice = Enum.reduce(frames, voice, fn f, v -> - :gen_udp.send( + :ok = :gen_udp.send( v.udp_socket, v.ip |> ip_to_tuple(), v.port, diff --git a/lib/nostrum/voice/ports.ex b/lib/nostrum/voice/ports.ex index 6fa280f55..8dbf7a973 100644 --- a/lib/nostrum/voice/ports.ex +++ b/lib/nostrum/voice/ports.ex @@ -22,6 +22,8 @@ defmodule Nostrum.Voice.Ports do end end + @dialyzer {:nowarn_function, init: 1} + alias Nostrum.Voice.Ports.State require Logger @@ -41,7 +43,7 @@ defmodule Nostrum.Voice.Ports do # Spawn process to asynchronously send input to port unless is_nil(input) do - Task.start(fn -> send_input(port, input) end) + {:ok, _pid} = Task.start(fn -> send_input(port, input) end) end # Store reference if input is another process diff --git a/lib/nostrum/voice/session.ex b/lib/nostrum/voice/session.ex index f9d4fa00d..f57370504 100644 --- a/lib/nostrum/voice/session.ex +++ b/lib/nostrum/voice/session.ex @@ -121,7 +121,7 @@ defmodule Nostrum.Voice.Session do ) do # Try to cancel the internal timer, but # do not explode if it was already cancelled. - :timer.cancel(state.heartbeat_ref) + _cancel_result = :timer.cancel(state.heartbeat_ref) {:noreply, state} end diff --git a/lib/nostrum/voice/supervisor.ex b/lib/nostrum/voice/supervisor.ex index 8d5e1d108..95972182a 100644 --- a/lib/nostrum/voice/supervisor.ex +++ b/lib/nostrum/voice/supervisor.ex @@ -32,6 +32,6 @@ defmodule Nostrum.Voice.Supervisor do restart: :transient } - DynamicSupervisor.start_child(Nostrum.Voice.SessionSupervisor, child) + {:ok, _pid} = DynamicSupervisor.start_child(Nostrum.Voice.SessionSupervisor, child) end end