From 28af5e3bd7073980465c1f6c1b2f6019c4a45e4f Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Fri, 26 Jan 2024 17:21:48 -0500 Subject: [PATCH 1/9] TwitterAPI.UtilController: fix dialyzer errors lib/pleroma/web/twitter_api/controllers/util_controller.ex:300:pattern_match The pattern can never match the type. Pattern: {:error, :no_such_alias} Type: {:not_found, nil} lib/pleroma/web/twitter_api/controllers/util_controller.ex:304:pattern_match The pattern can never match the type. Pattern: {:error, _error} Type: {:not_found, nil} --- lib/pleroma/web/twitter_api/controllers/util_controller.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pleroma/web/twitter_api/controllers/util_controller.ex b/lib/pleroma/web/twitter_api/controllers/util_controller.ex index 50f8f803f..c8ecf5eff 100644 --- a/lib/pleroma/web/twitter_api/controllers/util_controller.ex +++ b/lib/pleroma/web/twitter_api/controllers/util_controller.ex @@ -319,7 +319,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilController do user = User.get_cached_by_nickname(nickname) if user == nil do - {:not_found, nil} + {:error, :not_found} else {:ok, user} end From 06b8923d4222b617aeeffd507aa2bf7aa5943de1 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Fri, 26 Jan 2024 17:37:32 -0500 Subject: [PATCH 2/9] RichMedia.Parser.TTL.AwsSignedUrl: dialyzer fix lib/pleroma/web/rich_media/parser/ttl/aws_signed_url.ex:9:callback_type_mismatch Type mismatch for @callback ttl/2 in Pleroma.Web.RichMedia.Parser.TTL behaviour. Expected type: nil | integer() Actual type: {:error, <<_::64, _::size(8)>>} | {:ok, integer()} --- lib/pleroma/web/rich_media/parser.ex | 2 +- lib/pleroma/web/rich_media/parser/ttl/aws_signed_url.ex | 2 +- test/pleroma/web/rich_media/parser/ttl/aws_signed_url_test.exs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/pleroma/web/rich_media/parser.ex b/lib/pleroma/web/rich_media/parser.ex index 17a6ad617..837182d8a 100644 --- a/lib/pleroma/web/rich_media/parser.ex +++ b/lib/pleroma/web/rich_media/parser.ex @@ -105,7 +105,7 @@ defmodule Pleroma.Web.RichMedia.Parser do {:ok, integer() | :noop} | {:error, :no_key} def set_ttl_based_on_image(data, url) do case get_ttl_from_image(data, url) do - {:ok, ttl} when is_number(ttl) -> + ttl when is_number(ttl) -> ttl = ttl * 1000 case @cachex.expire_at(:rich_media_cache, url, ttl) do diff --git a/lib/pleroma/web/rich_media/parser/ttl/aws_signed_url.ex b/lib/pleroma/web/rich_media/parser/ttl/aws_signed_url.ex index fa41c160d..c8c869792 100644 --- a/lib/pleroma/web/rich_media/parser/ttl/aws_signed_url.ex +++ b/lib/pleroma/web/rich_media/parser/ttl/aws_signed_url.ex @@ -45,6 +45,6 @@ defmodule Pleroma.Web.RichMedia.Parser.TTL.AwsSignedUrl do |> Map.get("X-Amz-Date") |> Timex.parse("{ISO:Basic:Z}") - {:ok, Timex.to_unix(date) + String.to_integer(Map.get(params, "X-Amz-Expires"))} + Timex.to_unix(date) + String.to_integer(Map.get(params, "X-Amz-Expires")) end end diff --git a/test/pleroma/web/rich_media/parser/ttl/aws_signed_url_test.exs b/test/pleroma/web/rich_media/parser/ttl/aws_signed_url_test.exs index 59b3330ba..b90f7d9e2 100644 --- a/test/pleroma/web/rich_media/parser/ttl/aws_signed_url_test.exs +++ b/test/pleroma/web/rich_media/parser/ttl/aws_signed_url_test.exs @@ -22,7 +22,7 @@ defmodule Pleroma.Web.RichMedia.Parser.TTL.AwsSignedUrlTest do expire_time = Timex.parse!(timestamp, "{ISO:Basic:Z}") |> Timex.to_unix() |> Kernel.+(valid_till) - assert {:ok, expire_time} == Pleroma.Web.RichMedia.Parser.TTL.AwsSignedUrl.ttl(metadata, url) + assert expire_time == Pleroma.Web.RichMedia.Parser.TTL.AwsSignedUrl.ttl(metadata, url) end test "s3 signed url is parsed and correct ttl is set for rich media" do From 87cf7010fc865f37f518d51e9b41e91cb0524bbe Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Fri, 26 Jan 2024 19:09:38 -0500 Subject: [PATCH 3/9] Pleroma.Upload: dialyzer error I have opted to set this to :upper as this retains the same behavior but clears up the error. lib/pleroma/upload.ex:178:call The function call will not succeed. Base.encode16(binary(), [{:lower, true}]) breaks the contract (binary(), [{:case, encode_case()}]) :: binary() --- lib/pleroma/upload.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pleroma/upload.ex b/lib/pleroma/upload.ex index 3c355e64d..89cd3d920 100644 --- a/lib/pleroma/upload.ex +++ b/lib/pleroma/upload.ex @@ -175,7 +175,7 @@ defmodule Pleroma.Upload do defp prepare_upload(%{img: "data:image/" <> image_data}, opts) do parsed = Regex.named_captures(~r/(?jpeg|png|gif);base64,(?.*)/, image_data) data = Base.decode64!(parsed["data"], ignore: :whitespace) - hash = Base.encode16(:crypto.hash(:sha256, data), lower: true) + hash = Base.encode16(:crypto.hash(:sha256, data), case: :upper) with :ok <- check_binary_size(data, opts.size_limit), tmp_path <- tempfile_for_image(data), From 1b40ebfa2040da1bc80c5bbd50aff0f764d7c523 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Fri, 26 Jan 2024 19:21:43 -0500 Subject: [PATCH 4/9] Pleroma.Signature: dialyzer error lib/pleroma/signature.ex:30:pattern_match The pattern can never match the type. Pattern: %{<<97, 112, 95, 105, 100>> => _ap_id} Type: {:error, _} | {:ok, map()} --- lib/pleroma/signature.ex | 2 +- test/pleroma/signature_test.exs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/pleroma/signature.ex b/lib/pleroma/signature.ex index 5cfdae051..8fd422a6e 100644 --- a/lib/pleroma/signature.ex +++ b/lib/pleroma/signature.ex @@ -27,7 +27,7 @@ defmodule Pleroma.Signature do _ -> case Pleroma.Web.WebFinger.finger(maybe_ap_id) do - %{"ap_id" => ap_id} -> {:ok, ap_id} + {:ok, %{"ap_id" => ap_id}} -> {:ok, ap_id} _ -> {:error, maybe_ap_id} end end diff --git a/test/pleroma/signature_test.exs b/test/pleroma/signature_test.exs index f5a915fa8..8edf67a7b 100644 --- a/test/pleroma/signature_test.exs +++ b/test/pleroma/signature_test.exs @@ -113,7 +113,7 @@ defmodule Pleroma.SignatureTest do test "it calls webfinger for 'acct:' accounts" do with_mock(Pleroma.Web.WebFinger, - finger: fn _ -> %{"ap_id" => "https://gensokyo.2hu/users/raymoo"} end + finger: fn _ -> {:ok, %{"ap_id" => "https://gensokyo.2hu/users/raymoo"}} end ) do assert Signature.key_id_to_actor_id("acct:raymoo@gensokyo.2hu") == {:ok, "https://gensokyo.2hu/users/raymoo"} From e834343496f98685079a4ed070573c23069f7a20 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Fri, 26 Jan 2024 19:26:11 -0500 Subject: [PATCH 5/9] Pleroma.Search.SearchBackend: dialyzer error Incorrect spec. Both search backends return :ok so that is what should be the spec. lib/pleroma/search/database_search.ex:56:callback_type_mismatch Type mismatch for @callback remove_from_index/1 in Pleroma.Search.SearchBackend behaviour. Expected type: {:error, _} | {:ok, _} Actual type: :ok --- lib/pleroma/search/search_backend.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pleroma/search/search_backend.ex b/lib/pleroma/search/search_backend.ex index 46be84551..68bc48cec 100644 --- a/lib/pleroma/search/search_backend.ex +++ b/lib/pleroma/search/search_backend.ex @@ -20,5 +20,5 @@ defmodule Pleroma.Search.SearchBackend do is what contains the actual content and there is no need for filtering when removing from index. """ - @callback remove_from_index(object :: Pleroma.Object.t()) :: {:ok, any()} | {:error, any()} + @callback remove_from_index(object :: Pleroma.Object.t()) :: :ok | {:error, any()} end From 6e0945354d569a11c8995b65972db29811054128 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Fri, 26 Jan 2024 20:44:14 -0500 Subject: [PATCH 6/9] Pleroma.ModerationLog: fix invalid type --- lib/pleroma/moderation_log.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/pleroma/moderation_log.ex b/lib/pleroma/moderation_log.ex index 7203423e2..7f6962607 100644 --- a/lib/pleroma/moderation_log.ex +++ b/lib/pleroma/moderation_log.ex @@ -121,7 +121,7 @@ defmodule Pleroma.ModerationLog do defp prepare_log_data(attrs), do: attrs - @spec insert_log(log_params()) :: {:ok, ModerationLog} | {:error, any} + @spec insert_log(log_params()) :: {:ok, ModerationLog.t()} | {:error, any} def insert_log(%{actor: %User{}, subject: subjects, permission: permission} = attrs) do data = attrs @@ -248,7 +248,7 @@ defmodule Pleroma.ModerationLog do |> insert_log_entry_with_message() end - @spec insert_log_entry_with_message(ModerationLog) :: {:ok, ModerationLog} | {:error, any} + @spec insert_log_entry_with_message(ModerationLog.t()) :: {:ok, ModerationLog.t()} | {:error, any} defp insert_log_entry_with_message(entry) do entry.data["message"] |> put_in(get_log_entry_message(entry)) From b2ab479488660ac6d427a39027fd83df7a156c79 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Fri, 26 Jan 2024 20:57:46 -0500 Subject: [PATCH 7/9] Pleroma.Helpers.QtFastStart: Dialzyer error lib/pleroma/helpers/qt_fast_start.ex:129:improper_list_constr List construction (cons) will produce an improper list, because its second argument is <<_::32>>. lib/pleroma/helpers/qt_fast_start.ex:129:improper_list_constr List construction (cons) will produce an improper list, because its second argument is <<_::64>>. --- lib/pleroma/helpers/qt_fast_start.ex | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/pleroma/helpers/qt_fast_start.ex b/lib/pleroma/helpers/qt_fast_start.ex index 919fec84a..0b200b234 100644 --- a/lib/pleroma/helpers/qt_fast_start.ex +++ b/lib/pleroma/helpers/qt_fast_start.ex @@ -126,9 +126,15 @@ defmodule Pleroma.Helpers.QtFastStart do <>, acc ) do - rewrite_entries(unquote(size), offset, rest, [ - acc | <> - ]) + rewrite_entries( + unquote(size), + offset, + rest, + acc ++ + [ + <> + ] + ) end end From 7d7662277c99f70df6eab44ad394067721fbf177 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Fri, 26 Jan 2024 21:04:59 -0500 Subject: [PATCH 8/9] Changelog --- changelog.d/dialyzer2.skip | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 changelog.d/dialyzer2.skip diff --git a/changelog.d/dialyzer2.skip b/changelog.d/dialyzer2.skip new file mode 100644 index 000000000..e69de29bb From 6fcecbd48ba7e5f84d55eda43f386714f6a44d8c Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Sat, 27 Jan 2024 10:09:20 -0500 Subject: [PATCH 9/9] Formatting --- lib/pleroma/moderation_log.ex | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/pleroma/moderation_log.ex b/lib/pleroma/moderation_log.ex index 7f6962607..5c3ca58b0 100644 --- a/lib/pleroma/moderation_log.ex +++ b/lib/pleroma/moderation_log.ex @@ -248,7 +248,8 @@ defmodule Pleroma.ModerationLog do |> insert_log_entry_with_message() end - @spec insert_log_entry_with_message(ModerationLog.t()) :: {:ok, ModerationLog.t()} | {:error, any} + @spec insert_log_entry_with_message(ModerationLog.t()) :: + {:ok, ModerationLog.t()} | {:error, any} defp insert_log_entry_with_message(entry) do entry.data["message"] |> put_in(get_log_entry_message(entry))