ex-aws / ex_aws_s3

165 stars 146 forks source link

dialyzer "no_return" on ExAws.S3.presigned_post #254

Open unenglishable opened 5 months ago

unenglishable commented 5 months ago

Environment

Elixir 1.14.4 (compiled with Erlang/OTP 25)
* ex_aws 2.5.3 (Hex package) (mix)
  locked at 2.5.3 (ex_aws) 67115f1d
* ex_aws_s3 2.5.3 (Hex package) (mix)
  locked at 2.5.3 (ex_aws_s3) 4f09dd37
* hackney 1.20.1 (Hex package) (rebar3)
  locked at 1.20.1 (hackney) fe9094e5

Current behavior

code sample:

  def generate_presigned_post(%{filename: filename}) do
    config = Application.get_env(:server, __MODULE__)

    opts = [
      expires_in: config[:expire_after_hours],
      content_length_range: [config[:min_size_bytes], config[:max_size_bytes]],
      virtual_host: config[:virtual_host],
      starts_with: ["$Content-Type", config[:content_type_starts_with]]
    ]

    ExAws.Config.new(:s3, [])
    |> ExAws.S3.presigned_post(config[:bucket], config[:path] <> filename, opts)
  end

errors and stacktraces

> mix dialyzer

...
((module calling generate_presigned_post)):no_return
The created anonymous function has no local return.
________________________________________________________________________________
lib/server/s3.ex:10:no_return
Function generate_presigned_post/1 has no local return.
________________________________________________________________________________
done (warnings were emitted)
Halting VM with exit status 2

Expected behavior

dialyzer should succeed

when i remove the call to ExAws.S3.presigned_post dialyzer succeeds; it is the bottom function call in my project

this may be due to a bad @spec somewhere, i've recently fixed this issue by updating a @spec

i am fixing this temporarily in my project by configuring dialyzer to ignore generate_presigned_post

thank you for your consideration :)

sc-yan commented 2 weeks ago

I had same issue with this function, stream_file. mix dialyzer would fail since the func is calling File.stream! under the hood, but S3.Upload.stream_file is not ending with ! mark.

the issue is fixed by this PR. I fixed it by upgrading ex_aws_s3 from 2.3 to 2.5.3.