From c15e3c482786d47fe5cdc3561b8c3ded9bfe11ed Mon Sep 17 00:00:00 2001 From: Brandt Hill Date: Wed, 1 Nov 2023 13:17:59 -0500 Subject: [PATCH 1/4] Change instances of warn to warning --- lib/nostrum/shard/dispatch.ex | 2 +- lib/nostrum/shard/event.ex | 2 +- lib/nostrum/shard/session.ex | 2 +- lib/nostrum/shard/supervisor.ex | 4 ++-- lib/nostrum/voice/event.ex | 2 +- lib/nostrum/voice/session.ex | 4 ++-- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/nostrum/shard/dispatch.ex b/lib/nostrum/shard/dispatch.ex index bfb44d3f3..c51a1e260 100644 --- a/lib/nostrum/shard/dispatch.ex +++ b/lib/nostrum/shard/dispatch.ex @@ -405,7 +405,7 @@ defmodule Nostrum.Shard.Dispatch do end def handle_event(event, p, state) do - Logger.warn("UNHANDLED GATEWAY DISPATCH EVENT TYPE: #{event}, #{inspect(p)}") + Logger.warning("UNHANDLED GATEWAY DISPATCH EVENT TYPE: #{event}, #{inspect(p)}") {event, p, state} end end diff --git a/lib/nostrum/shard/event.ex b/lib/nostrum/shard/event.ex index 57703cd73..e6d424fde 100644 --- a/lib/nostrum/shard/event.ex +++ b/lib/nostrum/shard/event.ex @@ -67,7 +67,7 @@ defmodule Nostrum.Shard.Event do end def handle(event, _payload, state) do - Logger.warn("UNHANDLED GATEWAY EVENT #{event}") + Logger.warning("UNHANDLED GATEWAY EVENT #{event}") {state, []} end diff --git a/lib/nostrum/shard/session.ex b/lib/nostrum/shard/session.ex index 4c21c7ce2..174dab7d4 100644 --- a/lib/nostrum/shard/session.ex +++ b/lib/nostrum/shard/session.ex @@ -321,7 +321,7 @@ defmodule Nostrum.Shard.Session do heartbeat_later} else # Our last heartbeat was not acknowledged. Disconnect and try to resume. - Logger.warn("Heartbeat ack not received in time, reconnecting") + Logger.warning("Heartbeat ack not received in time, reconnecting") :ok = :gun.ws_send(conn, stream, :close) connect = {:next_event, :internal, :connect} {:next_state, :disconnected, %{data | stream: nil}, connect} diff --git a/lib/nostrum/shard/supervisor.ex b/lib/nostrum/shard/supervisor.ex index 0fd84acb7..c3c9d7b7b 100644 --- a/lib/nostrum/shard/supervisor.ex +++ b/lib/nostrum/shard/supervisor.ex @@ -19,7 +19,7 @@ defmodule Nostrum.Shard.Supervisor do 3. The payload is then written to the cache. To make sure we're not overrunning the cache, especially at startup with `request_guild_members` or other heavy - payloads, this is done in the shard itself. + payloads, this is done in the shard itself. 4. The cache updates itself from the new data. In some cases, such as update or delete events, it may send out a second "old" object as well, that helps the @@ -48,7 +48,7 @@ defmodule Nostrum.Shard.Supervisor do defp cast_shard_range(gateway_shards, gateway_shards), do: {1, gateway_shards, gateway_shards} defp cast_shard_range(gateway_shards, count) when is_integer(count) and count > 0 do - Logger.warn( + Logger.warning( "Configured shard count (#{count}) " <> "differs from Discord Gateway's recommended shard count (#{gateway_shards}). " <> "Consider using `num_shards: :auto` option in your Nostrum config." diff --git a/lib/nostrum/voice/event.ex b/lib/nostrum/voice/event.ex index 87565d517..ef3717540 100644 --- a/lib/nostrum/voice/event.ex +++ b/lib/nostrum/voice/event.ex @@ -99,7 +99,7 @@ defmodule Nostrum.Voice.Event do end def handle(event, _payload, state) do - Logger.warn("UNHANDLED VOICE GATEWAY EVENT #{event}") + Logger.debug("UNHANDLED VOICE GATEWAY EVENT #{event}") state end end diff --git a/lib/nostrum/voice/session.ex b/lib/nostrum/voice/session.ex index 74f79e8de..2343918eb 100644 --- a/lib/nostrum/voice/session.ex +++ b/lib/nostrum/voice/session.ex @@ -128,7 +128,7 @@ defmodule Nostrum.Voice.Session do def handle_info({:gun_up, worker, _proto}, state) do stream = :gun.ws_upgrade(worker, @gateway_qs) {:upgrade, ["websocket"], _} = :gun.await(worker, stream, @timeout_ws_upgrade) - Logger.warn("Reconnected after connection broke") + Logger.warning("Reconnected after connection broke") {:noreply, %{state | heartbeat_ack: true}} end @@ -154,7 +154,7 @@ defmodule Nostrum.Voice.Session do end def handle_cast(:heartbeat, %{heartbeat_ack: false, heartbeat_ref: timer_ref} = state) do - Logger.warn("heartbeat_ack not received in time, disconnecting") + Logger.warning("heartbeat_ack not received in time, disconnecting") {:ok, :cancel} = :timer.cancel(timer_ref) :gun.ws_send(state.conn, state.stream, :close) {:noreply, state} From 3f7c34b1174c6a11f588ade932a82def63a53e89 Mon Sep 17 00:00:00 2001 From: Brandt Hill Date: Wed, 1 Nov 2023 13:18:40 -0500 Subject: [PATCH 2/4] Add a check for OTP 25.1 to clarify runtime errors due to :pg.monitor/2 --- lib/nostrum/application.ex | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/nostrum/application.ex b/lib/nostrum/application.ex index 270bb2ce3..ee5f75f95 100644 --- a/lib/nostrum/application.ex +++ b/lib/nostrum/application.ex @@ -22,6 +22,7 @@ defmodule Nostrum.Application do def start(_type, _args) do Token.check_token!() check_executables() + check_otp_version() Logger.add_translator({Nostrum.StateMachineTranslator, :translate}) children = [ @@ -46,19 +47,19 @@ defmodule Nostrum.Application do cond do is_binary(ff) and is_nil(System.find_executable(ff)) -> - Logger.warn(""" + Logger.warning(""" #{ff} was not found in your path. By default, Nostrum requires ffmpeg to use voice. If you don't intend to use voice with ffmpeg, configure :nostrum, :ffmpeg to nil to suppress. """) is_binary(yt) and is_nil(System.find_executable(yt)) -> - Logger.warn(""" + Logger.warning(""" #{yt} was not found in your path. Nostrum supports youtube-dl for voice. If you don't require youtube-dl support, configure :nostrum, :youtubedl to nil to suppress. """) is_binary(sl) and is_nil(System.find_executable(sl)) -> - Logger.warn(""" + Logger.warning(""" #{sl} was not found in your path. Nostrum supports streamlink for voice. If you don't require streamlink support, configure :nostrum, :streamlink to nil to suppress. """) @@ -67,4 +68,15 @@ defmodule Nostrum.Application do :ok end end + + defp check_otp_version() do + _module_info = :pg.module_info() + + unless function_exported?(:pg, :monitor, 2) do + Logger.critical(""" + Your Erlang/OTP version needs to be 25.1 or newer to use Nostrum 0.9 and newer. + Current major version: #{System.otp_release()} + """) + end + end end From 9b22275c31e181aab33e656aa7c914ffc71bda66 Mon Sep 17 00:00:00 2001 From: Brandt Hill Date: Wed, 1 Nov 2023 13:31:43 -0500 Subject: [PATCH 3/4] Gracefully set voice session logger metadata if cache is broken --- lib/nostrum/voice/session.ex | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/nostrum/voice/session.ex b/lib/nostrum/voice/session.ex index 2343918eb..f9d4fa00d 100644 --- a/lib/nostrum/voice/session.ex +++ b/lib/nostrum/voice/session.ex @@ -28,13 +28,13 @@ defmodule Nostrum.Voice.Session do end def handle_continue(%VoiceState{channel_id: channel_id, guild_id: guild_id} = voice, nil) do - %{name: guild_name, channels: %{^channel_id => %{name: channel_name}}} = - GuildCache.get!(guild_id) + case GuildCache.get(guild_id) do + {:ok, %{name: guild_name, channels: %{^channel_id => %{name: channel_name}}}} -> + Logger.metadata(guild: ~s|"#{guild_name}"|, channel: ~s|"#{channel_name}"|) - Logger.metadata( - guild: ~s|"#{guild_name}"|, - channel: ~s|"#{channel_name}"| - ) + _error -> + Logger.metadata(guild: guild_id, channel: channel_id) + end [host, port] = String.split(voice.gateway, ":") From 14ed75e967f4a01563ec57953a034f04a16fc2e3 Mon Sep 17 00:00:00 2001 From: Brandt Hill Date: Wed, 1 Nov 2023 13:38:45 -0500 Subject: [PATCH 4/4] lint --- lib/nostrum/application.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/nostrum/application.ex b/lib/nostrum/application.ex index ee5f75f95..d776280b0 100644 --- a/lib/nostrum/application.ex +++ b/lib/nostrum/application.ex @@ -69,7 +69,7 @@ defmodule Nostrum.Application do end end - defp check_otp_version() do + defp check_otp_version do _module_info = :pg.module_info() unless function_exported?(:pg, :monitor, 2) do