From 025e8cb6f434634e7f535158a9ebf79386859a92 Mon Sep 17 00:00:00 2001 From: Marc Neudert Date: Wed, 23 Aug 2023 14:55:48 +0200 Subject: [PATCH] Fix Elixir 1.15.0 deprecations --- lib/instream/connection/config.ex | 51 ++++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 15 deletions(-) diff --git a/lib/instream/connection/config.ex b/lib/instream/connection/config.ex index 17d8243..2a099ce 100644 --- a/lib/instream/connection/config.ex +++ b/lib/instream/connection/config.ex @@ -302,21 +302,42 @@ defmodule Instream.Connection.Config do Will issue a warning if potential misconfiguration is found. """ @spec validate(conn :: module) :: boolean - def validate(conn) do - with otp_app when not is_nil(otp_app) <- conn.config(:otp_app), - nil <- Application.get_env(otp_app, conn) do - _ = - Logger.warn(""" - Instream connection #{inspect(conn)} is configured to fetch its - configuration from the application #{inspect(otp_app)} but the - configuration is empty. - - If this is intended please set any value (except "nil") explicitly. - """) - - false - else - _ -> true + + if macro_exported?(Logger, :warning, 1) do + def validate(conn) do + with otp_app when not is_nil(otp_app) <- conn.config(:otp_app), + nil <- Application.get_env(otp_app, conn) do + _ = + Logger.warning(""" + Instream connection #{inspect(conn)} is configured to fetch its + configuration from the application #{inspect(otp_app)} but the + configuration is empty. + + If this is intended please set any value (except "nil") explicitly. + """) + + false + else + _ -> true + end + end + else + def validate(conn) do + with otp_app when not is_nil(otp_app) <- conn.config(:otp_app), + nil <- Application.get_env(otp_app, conn) do + _ = + Logger.warn(""" + Instream connection #{inspect(conn)} is configured to fetch its + configuration from the application #{inspect(otp_app)} but the + configuration is empty. + + If this is intended please set any value (except "nil") explicitly. + """) + + false + else + _ -> true + end end end end