danielberkompas/elasticsearch-elixir

Issue with dialyzer.

lilezek opened this issue · 1 comments

I'm new to elixir, so I might be wrong, but I think this line:

https://github.com/infinitered/elasticsearch-elixir/blob/master/lib/elasticsearch.ex#L20

Is wrong. The dyalizer is blaming me for a code like this:

{:ok, score} = Elasticsearch.post(ES.ElasticsearchCluster, "/user_score/score/#{userId}", scoreQuery(value))

With this error:

lib/.../user_state.ex:40:pattern_match
The pattern
{:ok, score}

can never match the type
{:error, _}

Hey @lilezek 👋

Good question. Actually, the type definition is correct. Dyalizer is complaining because the left side of your match clause will never match the error case.

It would be better to use a case statement instead.

case Elasticsearch.post(ES.ElasticsearchCluster, "/user_score/score/#{userId}", scoreQuery(value)) do 
  {:ok, score} -> <do something>
  {:error, error} -> <do something with error>
end