peburrows / goth

Elixir package for Oauth authentication via Google Cloud APIs
http://hexdocs.pm/goth
MIT License
289 stars 111 forks source link

Invalid typespec for Goth.Token.for_scope/1 #55

Closed coryodaniel closed 5 years ago

coryodaniel commented 5 years ago

Goth.Token.for_scope/1 has a typespec{:ok, t}, but I believe should be {:ok, t} | {:error, any()} as it will return HTTPoison errors.

Not the biggest of deals, but it makes downstream dialyzer a bit noisy.

Thanks for your work on this library. Its been super useful!

peburrows commented 5 years ago

Maybe I'm missing something, but I don't think there's a case where Goth.Token.for_scope/1 would do anything other than return {:ok, t} or raise a MatchError. Do you mind pointing out where the {:error, any()} could be returned from Token.for_scope/1?

coryodaniel commented 5 years ago

Sorry, it should return but ends up w a mismatch on L150 below. Disable your NIC and call it.

https://github.com/peburrows/goth/blob/ab55cd47c01698f81ca55c353f3737d498134d0d/lib/goth/token.ex#L150

https://github.com/peburrows/goth/blob/ab55cd47c01698f81ca55c353f3737d498134d0d/lib/goth/client.ex#L88

iex(2)> Goth.Token.for_scope("https://www.googleapis.com/auth/compute https://www.googleapis.com/auth/cloud-platform")
** (MatchError) no match of right hand side value: {:error, %HTTPoison.Error{id: nil, reason: :nxdomain}}
    (goth) lib/goth/token.ex:150: Goth.Token.retrieve_and_store!/2
iex(2)>
peburrows commented 5 years ago

Yep, been traveling, but hoping to get to this some time tomorrow.

coryodaniel commented 5 years ago

No rush was just adding an example for my own sanity!

coryodaniel commented 5 years ago

That looks like the fix!

peburrows commented 5 years ago

Just published to Hex as v1.1.0