riverrun/comeonin

`Comeonin.Argon2.check_pass/2` always return `{:error, binary()}` according to Dialyzer

hauleth opened this issue · 6 comments

I know it isn't true, but still, this is the warning I have when I am using Comeonin.Argon2.check_pass/2 with with macro:

apps/kokon/lib/kokon/accounts/sessions.ex:36: The pattern {'ok', _user@2} can never match the type {'error',<<_:64,_:_*8>>}

My code is:

# apps/kokon/lib/kokon/accounts/sessions.ex
@spec create(email(), Password.password) :: {:ok, Session.t} | :error
def create(email, password) do
  user =
    User
    |> where(email: ^email)
    |> Repo.one

  with {:ok, user}    <- Password.check(user, password), # Line 36 from dialyse warning
       {:ok, session} <- Session.new(user) |> Repo.insert
  do
    {:ok, session}
  else
    {:error, reason} ->
      Logger.warn(fn ->
        "Failed to create user session: #{inspect reason}"
      end)

      :error
    _ -> :error
  end
end

And Password module has defdelegate to Comeonin.Argon2.check_pass/2:

@type password :: binary()
@type user :: %{password_hash: hash()}

@hasher Application.get_env(:kokon, __MODULE__, []) |> Keyword.fetch!(:hasher)

@spec check(user() | nil, password()) :: {:ok, user()} | {:error, binary()}
defdelegate check(user, password), to: @hasher, as: :check_pass

This error is quite irritating as GitLab CI do not build cache after failed jobs even when allow_failure is set to true, so my Dialyzer's PLT files aren't cached (and it is quite expensive operation in matter of time.

If you haven't done so already, could you open a dialyzer issue? Hopefully, they can give us more information about how to solve this problem.

@riverrun to be honest I do not know to which repo this should go:

  • Elixir - as I believe this issue with code generation (I have had similar issue with other fragment where I have been generating functions inside for comprehension)
  • OTP - as this is where Dialyzer code resides
  • Dialyxir - as this is ran through it

Try dialyxir first. If nothing else, there might be a way to silence the errors, like adding an annotation to the check_pass function.

Do you have any news about this issue?

Closing this issue for now. If you have any further updates to this, feel free to reopen this issue.

NobbZ commented

This is a bug in riverrun/argon2_elixir and gets fixed by riverrun/argon2_elixir#21.