Dialyzer error in `Plug.Conn.assign/2`

Hello,

I’m triing to start using dialyzer in one project and I keep getting this error:

lib/test.ex:11:call
The function call will not succeed.

Plug.Conn.assign(
  %Plug.Conn{
    :adapter => {Plug.MissingAdapter, nil},
    :assigns => %{},
    :before_send => [],
    :body_params => %Plug.Conn.Unfetched{:aspect => :body_params},
    :cookies => %Plug.Conn.Unfetched{:aspect => :cookies},
    :halted => false,
    :host => <<_::120>>,
    :method => <<_::24>>,
    :owner => nil,
    :params => %Plug.Conn.Unfetched{:aspect => :params},
    :path_info => [],
    :path_params => %{},
    :port => 0,
    :private => %{:phoenix_endpoint => Test.Endpoint},
    :query_params => %Plug.Conn.Unfetched{:aspect => :query_params},
    :query_string => <<>>,
    :remote_ip => {127, 0, 0, 1},
    :req_cookies => %Plug.Conn.Unfetched{:aspect => :cookies},
    :req_headers => [],
    :request_path => <<>>,
    :resp_body => nil,
    :resp_cookies => %{},
    :resp_headers => [{<<_::104>>, <<_::280>>}, ...],
    :scheme => :http,
    :script_name => [],
    :secret_key_base => nil,
    :state => :unset,
    :status => nil
  },
  :transaction,
  :test
)

breaks the contract
(t(), atom(), term()) :: t()

in code

defmodule Test do
  def plug do
    %Plug.Conn{
      remote_ip: {127, 0, 0, 1},
      private: %{phoenix_endpoint: Test.Endpoint}
    }
    |> Plug.Conn.assign(:transaction, :test)
  end
end

I’m out of ideas, mainly because it is so simple piece of code. Anyone experienced such error and know how to solve it?

ˋ:ownerˋ in the conn is typed as ˋpidˋ, but is nil in your case. This is likely because you‘re manually building the struct.

1 Like