Skip to content

Commit

Permalink
fix(gax): invalid spec in Connection/Response modules
Browse files Browse the repository at this point in the history
It may trigger invalid dialyzer warnings in apps.

For example, for this piece of code:

```elixir
case Client.indexing_url_notifications_publish( connection, [ {:body, payload} ]) do
  {:ok, _} -> :ok
  {:error, %{status: 429}} -> {:discard, "Rate-limiting error, please check the quota."}
  {:error, :timeout} -> ...
end
```

For the clause `{:error, :timeout}`, dialyzer says `The pattern can never match the type`.
However, it is possible to have `{:error, :timeout}` when Connection fails (because of a timeout).
  • Loading branch information
davidjulien committed Sep 26, 2024
1 parent b73d0a3 commit 3356510
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion clients/gax/lib/google_api/gax/connection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ defmodule GoogleApi.Gax.Connection do
* `{:ok, Tesla.Env.t}` - If the call was successful
* `{:error, reason}` - If the call failed
"""
@spec execute(Tesla.Client.t(), GoogleApi.Gax.Request.t()) :: {:ok, Tesla.Env.t()}
@spec execute(Tesla.Client.t(), GoogleApi.Gax.Request.t()) :: Tesla.Env.result()
def execute(connection, request) do
request
|> GoogleApi.Gax.Connection.build_request()
Expand Down
8 changes: 4 additions & 4 deletions clients/gax/lib/google_api/gax/response.ex
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@ defmodule GoogleApi.Gax.Response do
## Parameters
* `response` (*type:* `{:ok, Tesla.Env.t} | {:error, reason}`) - The response object
* `response` (*type:* `Testla.Env.result()`) - The response object
* `opts` (*type:* `keyword()`) - [optional] Optional parameters
* `:dataWrapped` (*type:* `boolean()`) - If true, the remove the wrapping "data" field. Defaults to false.
* `:decode` (*type:* `boolean()`) - If false, returns the entire reponse. Defaults to true.
* `:struct` (*type:* `module`)
## Returns
* `{:ok, struct()}` on success
* `{:error, Tesla.Env.t}` on failure
* `{:ok, nil | struct()}` on success
* `{:error, any() | Tesla.Env.t}` on failure
"""
@spec decode({:ok, Tesla.Env.t()}, keyword()) :: {:ok, struct()} | {:error, Tesla.Env.t()}
@spec decode(Tesla.Env.result(), keyword()) :: {:ok, nil | struct()} | {:error, any() | Tesla.Env.t()}
def decode(env, opts \\ [])

def decode({:error, reason}, _), do: {:error, reason}
Expand Down

0 comments on commit 3356510

Please sign in to comment.