logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git
commit: 81afaee37436f1802f4e0a6d33d9bb8121e51f48
parent 75ea766824a5d7714fbea5d24e59444c7adfc274
Author: Ilja <ilja@ilja.space>
Date:   Tue, 22 Feb 2022 18:18:10 +0100

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.

Diffstat:

Mlib/pleroma/config/deprecation_warnings.ex2+-
Mtest/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 @@ -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 @@ -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