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.
This commit is contained in:
Ilja 2022-02-22 18:18:10 +01:00
parent 75ea766824
commit 81afaee374
2 changed files with 2 additions and 2 deletions

View file

@ -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("""

View file

@ -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