I’m having an issue getting my Dialyzer to agree with my output, and can’t seem to figure it out. Essentially, the response is {:error, %Mint.HTTP2{}, %Mint.HTTPError{}} instead of just {:error, _} and I can’t get the spec to reflect that.
This is the issue I’m facing, I keep getting an error from my Mint transport service (which is a whole separate issue) but I keep getting alerts that my handle_response isn’t able to match the type. After looking into it more the error tuple has two arguments in the shape of: {:error, %Mint.HTTP2{}, %Mint.HTTPError{}}.
Here is my handle_response:
@spec handle_response(
{:ok, [map()] | function()}
| {:error, String.t()}
| {:error, %Mint.HTTP2{}, %Mint.HTTPError{}},
Keyword.t()
) ::
{:ok, [map()] | function()} | {:error, term()}
defp handle_response(resp, opts)
defp handle_response({:ok, stream} = resp, stream: true) when is_function(stream), do: resp
defp handle_response({:ok, resp}, opts) when is_binary(resp),
do: handle_response({:ok, Jason.decode!(resp)}, opts)
defp handle_response({:ok, resp}, _), do: {:ok, Map.get(resp, "choices", [])}
defp handle_response({:error, _} = err, _), do: err
defp handle_response({:error, http, http_error}, _)
when is_map(http) and is_map(http_error),
do: {:error, http_error}
But I keep getting an error from my dialyzer here:
lib/broadcast.ex:129:pattern_match
The pattern can never match the type.
Pattern:
{:error, _http, _http_error}, _
Type:
{:error, _} | {:ok, _}, [{:stream, _}, ...]
I’m not sure why, I’m pretty sure the spec should be correct. Can anyone see what would be incorrect about this or does this seem reasonable?