Pleroma.Web.PleromaAPI.EmojiFileController: dialyzer errors

lib/pleroma/web/pleroma_api/controllers/emoji_file_controller.ex:52:no_return
Function update/2 has no local return.
________________________________________________________________________________
lib/pleroma/web/pleroma_api/controllers/emoji_file_controller.ex:59:call
The function call will not succeed.

Phoenix.Controller.json(_conn :: %{:body_params => %{:shortcode => _, _ => _}, _ => _}, %{
  binary() =>
    binary()
    | maybe_improper_list(
        binary() | maybe_improper_list(any(), binary() | []) | char(),
        binary() | []
      )
})

breaks the contract
(Plug.Conn.t(), term()) :: Plug.Conn.t()

________________________________________________________________________________
lib/pleroma/web/pleroma_api/controllers/emoji_file_controller.ex:62:call
The function call will not succeed.

Plug.Conn.put_status(_conn :: %{:body_params => %{:shortcode => _, _ => _}, _ => _}, :conflict)

breaks the contract
(t(), status()) :: t()

________________________________________________________________________________
lib/pleroma/web/pleroma_api/controllers/emoji_file_controller.ex:70:call
The function call will not succeed.

Plug.Conn.put_status(_conn :: %{:body_params => %{:shortcode => _, _ => _}, _ => _}, :unprocessable_entity) ::
  :ok
def a() do
  :ok
end

breaks the contract
(t(), status()) :: t()

________________________________________________________________________________
lib/pleroma/web/pleroma_api/controllers/emoji_file_controller.ex:75:call
The function call will not succeed.

Pleroma.Web.PleromaAPI.EmojiFileController.handle_error(
  _conn :: %{:body_params => %{:shortcode => _, _ => _}, _ => _},
  _error :: {:error, atom()},
  %{:code => _, :message => <<_::328>>, :pack_name => binary()}
)

will never return since the 1st arguments differ
from the success typing arguments:

(
  %Plug.Conn{
    :adapter => {atom(), _},
    :assigns => %{atom() => _},
    :body_params => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
    :cookies => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
    :halted => boolean(),
    :host => binary(),
    :method => binary(),
    :owner => pid(),
    :params => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
    :path_info => [binary()],
    :path_params => %{
      binary() =>
        binary() | [binary() | [any()] | map()] | %{binary() => binary() | [any()] | map()}
    },
    :port => char(),
    :private => %{atom() => _},
    :query_params => %Plug.Conn.Unfetched{
      :aspect => atom(),
      binary() =>
        binary() | [binary() | [any()] | map()] | %{binary() => binary() | [any()] | map()}
    },
    :query_string => binary(),
    :remote_ip =>
      {byte(), byte(), byte(), byte()}
      | {char(), char(), char(), char(), char(), char(), char(), char()},
    :req_cookies => %Plug.Conn.Unfetched{:aspect => atom(), binary() => binary()},
    :req_headers => [{binary(), binary()}],
    :request_path => binary(),
    :resp_body =>
      nil
      | binary()
      | maybe_improper_list(
          binary() | maybe_improper_list(any(), binary() | []) | byte(),
          binary() | []
        ),
    :resp_cookies => %{binary() => map()},
    :resp_headers => [{binary(), binary()}],
    :scheme => :http | :https,
    :script_name => [binary()],
    :secret_key_base => nil | binary(),
    :state =>
      :chunked | :file | :sent | :set | :set_chunked | :set_file | :unset | :upgraded,
    :status => nil | non_neg_integer()
  },
  {:error, atom()},
  %{:message => <<_::328, _::size(88)>>, :pack_name => binary(), :code => _}
)

________________________________________________________________________________
lib/pleroma/web/pleroma_api/controllers/emoji_file_controller.ex:75:call
The function call will not succeed.

Pleroma.Web.PleromaAPI.EmojiFileController.handle_error(
  _conn :: %{:body_params => %{:shortcode => _, _ => _}, _ => _},
  _error :: {:error, atom()},
  %{:code => binary(), :message => <<_::328>>, :pack_name => binary()}
)

will never return since the 1st arguments differ
from the success typing arguments:

(
  %Plug.Conn{
    :adapter => {atom(), _},
    :assigns => %{atom() => _},
    :body_params => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
    :cookies => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
    :halted => boolean(),
    :host => binary(),
    :method => binary(),
    :owner => pid(),
    :params => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
    :path_info => [binary()],
    :path_params => %{
      binary() =>
        binary() | [binary() | [any()] | map()] | %{binary() => binary() | [any()] | map()}
    },
    :port => char(),
    :private => %{atom() => _},
    :query_params => %Plug.Conn.Unfetched{
      :aspect => atom(),
      binary() =>
        binary() | [binary() | [any()] | map()] | %{binary() => binary() | [any()] | map()}
    },
    :query_string => binary(),
    :remote_ip =>
      {byte(), byte(), byte(), byte()}
      | {char(), char(), char(), char(), char(), char(), char(), char()},
    :req_cookies => %Plug.Conn.Unfetched{:aspect => atom(), binary() => binary()},
    :req_headers => [{binary(), binary()}],
    :request_path => binary(),
    :resp_body =>
      nil
      | binary()
      | maybe_improper_list(
          binary() | maybe_improper_list(any(), binary() | []) | byte(),
          binary() | []
        ),
    :resp_cookies => %{binary() => map()},
    :resp_headers => [{binary(), binary()}],
    :scheme => :http | :https,
    :script_name => [binary()],
    :secret_key_base => nil | binary(),
    :state =>
      :chunked | :file | :sent | :set | :set_chunked | :set_file | :unset | :upgraded,
    :status => nil | non_neg_integer()
  },
  {:error, atom()},
  %{:message => <<_::328, _::size(88)>>, :pack_name => binary(), :code => _}
)
This commit is contained in:
Mark Felder 2024-01-28 14:07:35 -05:00
parent 77bf617c4b
commit dc912dc590
2 changed files with 18 additions and 18 deletions

View File

@ -36,9 +36,9 @@ defmodule Pleroma.Web.ApiSpec.PleromaEmojiFileOperation do
defp create_request do defp create_request do
%Schema{ %Schema{
type: :object, type: :object,
required: [:file], required: ["file"],
properties: %{ properties: %{
file: %Schema{ "file" => %Schema{
description: description:
"File needs to be uploaded with the multipart request or link to remote file", "File needs to be uploaded with the multipart request or link to remote file",
anyOf: [ anyOf: [
@ -46,12 +46,12 @@ defmodule Pleroma.Web.ApiSpec.PleromaEmojiFileOperation do
%Schema{type: :string, format: :uri} %Schema{type: :string, format: :uri}
] ]
}, },
shortcode: %Schema{ "shortcode" => %Schema{
type: :string, type: :string,
description: description:
"Shortcode for new emoji, must be unique for all emoji. If not sended, shortcode will be taken from original filename." "Shortcode for new emoji, must be unique for all emoji. If not sended, shortcode will be taken from original filename."
}, },
filename: %Schema{ "filename" => %Schema{
type: :string, type: :string,
description: description:
"New emoji file name. If not specified will be taken from original filename." "New emoji file name. If not specified will be taken from original filename."
@ -81,21 +81,21 @@ defmodule Pleroma.Web.ApiSpec.PleromaEmojiFileOperation do
defp update_request do defp update_request do
%Schema{ %Schema{
type: :object, type: :object,
required: [:shortcode, :new_shortcode, :new_filename], required: ["shortcode", "new_shortcode", "new_filename"],
properties: %{ properties: %{
shortcode: %Schema{ "shortcode" => %Schema{
type: :string, type: :string,
description: "Emoji file shortcode" description: "Emoji file shortcode"
}, },
new_shortcode: %Schema{ "new_shortcode" => %Schema{
type: :string, type: :string,
description: "New emoji file shortcode" description: "New emoji file shortcode"
}, },
new_filename: %Schema{ "new_filename" => %Schema{
type: :string, type: :string,
description: "New filename for emoji file" description: "New filename for emoji file"
}, },
force: %Schema{ "force" => %Schema{
type: :boolean, type: :boolean,
description: "With true value to overwrite existing emoji with new shortcode", description: "With true value to overwrite existing emoji with new shortcode",
default: false default: false

View File

@ -23,11 +23,11 @@ defmodule Pleroma.Web.PleromaAPI.EmojiFileController do
defdelegate open_api_operation(action), to: ApiSpec.PleromaEmojiFileOperation defdelegate open_api_operation(action), to: ApiSpec.PleromaEmojiFileOperation
def create(%{body_params: params} = conn, %{name: pack_name}) do def create(%{body_params: params} = conn, %{name: pack_name}) do
filename = params[:filename] || get_filename(params[:file]) filename = params["filename"] || get_filename(params["file"])
shortcode = params[:shortcode] || Path.basename(filename, Path.extname(filename)) shortcode = params["shortcode"] || Path.basename(filename, Path.extname(filename))
with {:ok, pack} <- Pack.load_pack(pack_name), with {:ok, pack} <- Pack.load_pack(pack_name),
{:ok, file} <- get_file(params[:file]), {:ok, file} <- get_file(params["file"]),
{:ok, pack} <- Pack.add_file(pack, shortcode, filename, file) do {:ok, pack} <- Pack.add_file(pack, shortcode, filename, file) do
json(conn, pack.files) json(conn, pack.files)
else else
@ -49,10 +49,10 @@ defmodule Pleroma.Web.PleromaAPI.EmojiFileController do
end end
end end
def update(%{body_params: %{shortcode: shortcode} = params} = conn, %{name: pack_name}) do def update(%{body_params: %{"shortcode" => shortcode} = params} = conn, %{name: pack_name}) do
new_shortcode = params[:new_shortcode] new_shortcode = params["new_shortcode"]
new_filename = params[:new_filename] new_filename = params["new_filename"]
force = params[:force] force = params["force"]
with {:ok, pack} <- Pack.load_pack(pack_name), with {:ok, pack} <- Pack.load_pack(pack_name),
{:ok, pack} <- Pack.update_file(pack, shortcode, new_shortcode, new_filename, force) do {:ok, pack} <- Pack.update_file(pack, shortcode, new_shortcode, new_filename, force) do
@ -128,9 +128,9 @@ defmodule Pleroma.Web.PleromaAPI.EmojiFileController do
defp get_filename(%Plug.Upload{filename: filename}), do: filename defp get_filename(%Plug.Upload{filename: filename}), do: filename
defp get_filename(url) when is_binary(url), do: Path.basename(url) defp get_filename(url) when is_binary(url), do: Path.basename(url)
def get_file(%Plug.Upload{} = file), do: {:ok, file} defp get_file(%Plug.Upload{} = file), do: {:ok, file}
def get_file(url) when is_binary(url) do defp get_file(url) when is_binary(url) do
with {:ok, %Tesla.Env{body: body, status: code, headers: headers}} with {:ok, %Tesla.Env{body: body, status: code, headers: headers}}
when code in 200..299 <- Pleroma.HTTP.get(url) do when code in 200..299 <- Pleroma.HTTP.get(url) do
path = Plug.Upload.random_file!("emoji") path = Plug.Upload.random_file!("emoji")