michalmuskala / plug_attack

A plug building toolkit for blocking and throttling abusive requests
420 stars 21 forks source link

Dialyzer Fails #12

Closed xanderdunn closed 6 years ago

xanderdunn commented 6 years ago

Elixir 1.5.3.
plug_attack 0.3.0 dialyzer 3.2.3

When I add a simple rule to my project:

defmodule MyApp.Plug.PlugAttack do
  @moduledoc """
  Block IP addresses.
  """

  import Plug.Conn
  use PlugAttack

  rule "allow local", conn do
    block conn.remote_ip == {127, 0, 0, 1}
  end

end

The code works as expected when I run the server. However, when I run dialyzer, I get this error:

dialyzer args: [check_plt: false,
 init_plt: '/local/dev/api-tournament/_build/dev/lib/dialyxir/plt_file.plt',
 files_rec: ['/local/dev/api-tournament/_build/dev/lib/api_tournament/ebin'],
 warnings: [:unmatched_returns]]
done in 0m3.91s
lib/plugs/plugattack.ex:1: The pattern {'block', _@4} can never match the type 'nil'
lib/plugs/plugattack.ex:1: The variable _@5 can never match since previous clauses completely covered the type 'nil' | {'allow',_}
done (warnings were emitted)

Unfortunately, I can't use this package in our production code because of this

michalmuskala commented 6 years ago

I pushed a commit that should hopefully fix it https://github.com/michalmuskala/plug_attack/commit/20465e7790408eee35277f30df18ea90d3fd51c4

Could you try it and see if it helps?

skylerparr commented 6 years ago

That commit worked for me.

michalmuskala commented 6 years ago

The fix was published in 0.3.1