From 81afaee37436f1802f4e0a6d33d9bb8121e51f48 Mon Sep 17 00:00:00 2001 From: Ilja Date: Tue, 22 Feb 2022 18:18:10 +0100 Subject: [PATCH] Better way of getting keys I used keyword_list[:key], but if the key doesn't exist, it will return nil. I actually expect a list and further down the code I use that list. I believe the key should always be present, but in case it's not, it's better to return an empty list instead of nil. That way the code wont fail further down the line. --- lib/pleroma/config/deprecation_warnings.ex | 2 +- test/pleroma/config/deprecation_warnings_test.exs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/pleroma/config/deprecation_warnings.ex b/lib/pleroma/config/deprecation_warnings.ex index 4348505e2..599f1d3cf 100644 --- a/lib/pleroma/config/deprecation_warnings.ex +++ b/lib/pleroma/config/deprecation_warnings.ex @@ -21,7 +21,7 @@ defmodule Pleroma.Config.DeprecationWarnings do ] def check_exiftool_filter do - filters = Config.get([Pleroma.Upload])[:filters] + filters = Config.get([Pleroma.Upload]) |> Keyword.get(:filters, []) if Pleroma.Upload.Filter.Exiftool in filters do Logger.warn(""" diff --git a/test/pleroma/config/deprecation_warnings_test.exs b/test/pleroma/config/deprecation_warnings_test.exs index ffd446909..f3453ddb0 100644 --- a/test/pleroma/config/deprecation_warnings_test.exs +++ b/test/pleroma/config/deprecation_warnings_test.exs @@ -51,7 +51,7 @@ defmodule Pleroma.Config.DeprecationWarningsTest do capture_log(fn -> DeprecationWarnings.warn() end) - assert Config.get([Pleroma.Upload])[:filters] == expected_config + assert Config.get([Pleroma.Upload]) |> Keyword.get(:filters, []) == expected_config end test "doesn't give a warning with correct config" do