summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIlja <ilja@ilja.space>2022-02-22 18:18:10 +0100
committerIlja <ilja@ilja.space>2022-07-01 12:15:02 +0200
commit81afaee37436f1802f4e0a6d33d9bb8121e51f48 (patch)
treef6a9cb47869589e0211c0a53ca41eaa202d4f569
parent75ea766824a5d7714fbea5d24e59444c7adfc274 (diff)
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.
-rw-r--r--lib/pleroma/config/deprecation_warnings.ex2
-rw-r--r--test/pleroma/config/deprecation_warnings_test.exs2
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