I’m using the https://github.com/GoogleCloudPlatform/elixir-google-api/tree/master/clients/sheets project (a thin wrapper over the Google Sheets API) to create a Google sheet. The module that creates the sheets for us has a number of Dialyzer warnings but they are all the same root cause I’d imagine. The warning is “Function get_spreadsheet/1 will never be called” (where get_spreadsheet/1 is just an example).
Here’s the lead to that issue:
defp create_google_sheet(nil) do
Logger.info("No spreadsheet exists, creating one")
month = @months[DateTime.utc_now().month]
create_google_connection()
|> Spreadsheets.sheets_spreadsheets_create(
body: %{properties: %{title: "#{month}-#{DateTime.utc_now().year}-Deployment/Build Report"}}
)
|> get_spreadsheet()
end
The get_spreadsheet is just a shim to parse out the {:ok, response} or :error returned by sheets_spreadsheets_create. Here’s the one
defp get_spreadsheet(result) do
case result do
{:ok, response} -> response
{:error, _env} -> nil
end
end
Spreadsheets.sheets_spreadsheets_create spec is:
@spec sheets_spreadsheets_create(Tesla.Env.client, keyword()) :: {:ok, GoogleApi.Sheets.V4.Model.Spreadsheet.t} | {:error, Tesla.Env.t}
This functions fine. We’ve been running it in production for a month or so and it does exactly what we want but it bothers me that I don’t understand what dialyzer is trying to tell me. Any suggestions on what to look at?
dom
May 17, 2018, 3:44pm
2
“Function get_spreadsheet/1 will never be called” is just fallout from the real error. What does dialyzer say before that?
NobbZ
May 17, 2018, 3:44pm
3
Dialyzed doesn’t see a valid way that create_google_sheet/1
will ever be called with nil argument therefore it assumes functions called from it will never be called.
At least that’s my assumption from what you have shown.
The first warning that Dialyzer outputs is related to that get_spreadsheet/1 call. it does not warn about the create_google_connection/0 or the Spreadsheets.sheets_spreadsheets_create function calls. If I make that get_spreadsheet function public it doesn’t change the warnings that dialyzer produces.
NobbZ
May 17, 2018, 4:15pm
5
Can you provide a minified project that produces similar warnings?
Or is the original projects source publicly available?
thanks. Let me get that together. its a private project for my company but I can extract this issue. will post again when its available.
NobbZ
May 17, 2018, 4:45pm
8
The PLT is building right now, I’ll take a look at it as my family gives me the time
1 Like
I’m kind of thinking it dies on the Spreadsheets.sheets_spreadsheets_create
call from just an initial look?
EDIT: This is the dialyzer results if anyone is curious on that repo:
lib/google_spreadsheet.ex:22: Function deployments_sheet/0 has no local return
lib/google_spreadsheet.ex:34: Function create_google_sheet/1 has no local return
lib/google_spreadsheet.ex:55: Function get_spreadsheet/1 will never be called
1 Like
NobbZ
May 17, 2018, 5:33pm
10
Its an upstream issue:
lib/google_api/sheets/v4/api/spreadsheets.ex:114: Function sheets_spreadsheets_create/1 has no local return
lib/google_api/sheets/v4/api/spreadsheets.ex:114: Function sheets_spreadsheets_create/2 has no local return
edit
I took the freedom to file an issue:
opened 09:40PM - 17 May 18 UTC
closed 05:22PM - 21 May 18 UTC
triage me
In a [thread in the elixirforum](https://elixirforum.com/t/another-dialyzer-puzz… le/14249) we discovered some issues with the `spec`s of your library.
A quick run against the `sheet` library (which ultimatively had the problems in the aforementioned thread) revealed the following warnings:
```plain
:0: Unknown type 'Elixir.GoogleApi.Sheets.V4.Model.AppendValuesResponse':t/0
:0: Unknown type 'Elixir.GoogleApi.Sheets.V4.Model.BatchClearValuesResponse':t/0
:0: Unknown type 'Elixir.GoogleApi.Sheets.V4.Model.BatchGetValuesResponse':t/0
:0: Unknown type 'Elixir.GoogleApi.Sheets.V4.Model.BatchUpdateSpreadsheetResponse':t/0
:0: Unknown type 'Elixir.GoogleApi.Sheets.V4.Model.BatchUpdateValuesResponse':t/0
:0: Unknown type 'Elixir.GoogleApi.Sheets.V4.Model.ClearValuesResponse':t/0
:0: Unknown type 'Elixir.GoogleApi.Sheets.V4.Model.SheetProperties':t/0
:0: Unknown type 'Elixir.GoogleApi.Sheets.V4.Model.Spreadsheet':t/0
:0: Unknown type 'Elixir.GoogleApi.Sheets.V4.Model.UpdateValuesResponse':t/0
:0: Unknown type 'Elixir.GoogleApi.Sheets.V4.Model.ValueRange':t/0
:0: Unknown type 'Elixir.Integer':t/0
:0: Unknown type 'Elixir.Map':t/0
lib/google_api/sheets/v4/api/spreadsheets.ex:58: Function sheets_spreadsheets_batch_update/2 has no local return
lib/google_api/sheets/v4/api/spreadsheets.ex:58: Function sheets_spreadsheets_batch_update/3 has no local return
lib/google_api/sheets/v4/api/spreadsheets.ex:76: The call 'Elixir.GoogleApi.Sheets.V4.RequestBuilder':method(#{},'post') breaks the contract (map(),'Elixir.String':t()) -> map()
lib/google_api/sheets/v4/api/spreadsheets.ex:114: Function sheets_spreadsheets_create/1 has no local return
lib/google_api/sheets/v4/api/spreadsheets.ex:114: Function sheets_spreadsheets_create/2 has no local return
lib/google_api/sheets/v4/api/spreadsheets.ex:132: The call 'Elixir.GoogleApi.Sheets.V4.RequestBuilder':method(#{},'post') breaks the contract (map(),'Elixir.String':t()) -> map()
lib/google_api/sheets/v4/api/spreadsheets.ex:170: Function sheets_spreadsheets_get/2 has no local return
lib/google_api/sheets/v4/api/spreadsheets.ex:170: Function sheets_spreadsheets_get/3 has no local return
lib/google_api/sheets/v4/api/spreadsheets.ex:189: The call 'Elixir.GoogleApi.Sheets.V4.RequestBuilder':method(#{},'get') breaks the contract (map(),'Elixir.String':t()) -> map()
lib/google_api/sheets/v4/api/spreadsheets.ex:229: Function sheets_spreadsheets_sheets_copy_to/3 has no local return
lib/google_api/sheets/v4/api/spreadsheets.ex:229: Function sheets_spreadsheets_sheets_copy_to/4 has no local return
lib/google_api/sheets/v4/api/spreadsheets.ex:247: The call 'Elixir.GoogleApi.Sheets.V4.RequestBuilder':method(#{},'post') breaks the contract (map(),'Elixir.String':t()) -> map()
lib/google_api/sheets/v4/api/spreadsheets.ex:293: Function sheets_spreadsheets_values_append/3 has no local return
lib/google_api/sheets/v4/api/spreadsheets.ex:293: Function sheets_spreadsheets_values_append/4 has no local return
lib/google_api/sheets/v4/api/spreadsheets.ex:316: The call 'Elixir.GoogleApi.Sheets.V4.RequestBuilder':method(#{},'post') breaks the contract (map(),'Elixir.String':t()) -> map()
lib/google_api/sheets/v4/api/spreadsheets.ex:356: Function sheets_spreadsheets_values_batch_clear/2 has no local return
lib/google_api/sheets/v4/api/spreadsheets.ex:356: Function sheets_spreadsheets_values_batch_clear/3 has no local return
lib/google_api/sheets/v4/api/spreadsheets.ex:374: The call 'Elixir.GoogleApi.Sheets.V4.RequestBuilder':method(#{},'post') breaks the contract (map(),'Elixir.String':t()) -> map()
lib/google_api/sheets/v4/api/spreadsheets.ex:416: Function sheets_spreadsheets_values_batch_get/2 has no local return
lib/google_api/sheets/v4/api/spreadsheets.ex:416: Function sheets_spreadsheets_values_batch_get/3 has no local return
lib/google_api/sheets/v4/api/spreadsheets.ex:437: The call 'Elixir.GoogleApi.Sheets.V4.RequestBuilder':method(#{},'get') breaks the contract (map(),'Elixir.String':t()) -> map()
lib/google_api/sheets/v4/api/spreadsheets.ex:476: Function sheets_spreadsheets_values_batch_update/2 has no local return
lib/google_api/sheets/v4/api/spreadsheets.ex:476: Function sheets_spreadsheets_values_batch_update/3 has no local return
lib/google_api/sheets/v4/api/spreadsheets.ex:494: The call 'Elixir.GoogleApi.Sheets.V4.RequestBuilder':method(#{},'post') breaks the contract (map(),'Elixir.String':t()) -> map()
lib/google_api/sheets/v4/api/spreadsheets.ex:534: Function sheets_spreadsheets_values_clear/3 has no local return
lib/google_api/sheets/v4/api/spreadsheets.ex:534: Function sheets_spreadsheets_values_clear/4 has no local return
lib/google_api/sheets/v4/api/spreadsheets.ex:552: The call 'Elixir.GoogleApi.Sheets.V4.RequestBuilder':method(#{},'post') breaks the contract (map(),'Elixir.String':t()) -> map()
lib/google_api/sheets/v4/api/spreadsheets.ex:595: Function sheets_spreadsheets_values_get/3 has no local return
lib/google_api/sheets/v4/api/spreadsheets.ex:595: Function sheets_spreadsheets_values_get/4 has no local return
lib/google_api/sheets/v4/api/spreadsheets.ex:615: The call 'Elixir.GoogleApi.Sheets.V4.RequestBuilder':method(#{},'get') breaks the contract (map(),'Elixir.String':t()) -> map()
lib/google_api/sheets/v4/api/spreadsheets.ex:660: Function sheets_spreadsheets_values_update/3 has no local return
lib/google_api/sheets/v4/api/spreadsheets.ex:660: Function sheets_spreadsheets_values_update/4 has no local return
lib/google_api/sheets/v4/api/spreadsheets.ex:682: The call 'Elixir.GoogleApi.Sheets.V4.RequestBuilder':method(#{},'put') breaks the contract (map(),'Elixir.String':t()) -> map()
lib/google_api/sheets/v4/deserializer.ex:28: Invalid type specification for function 'Elixir.GoogleApi.Sheets.V4.Deserializer':deserialize/5. The success typing is (_,_,'date' | 'list' | 'map' | 'struct',_,_) -> any()
lib/google_api/sheets/v4/deserializer.ex:45: The pattern {'ok', Vdatetime@1} can never match the type {'error','invalid_date' | 'invalid_format' | 'invalid_time' | 'missing_offset'} | {'ok',#{'__struct__':='Elixir.DateTime', 'calendar':=atom(), 'day':=integer(), 'hour':=integer(), 'microsecond':={char(),0 | 1 | 2 | 3 | 4 | 5 | 6}, 'minute':=integer(), 'month':=integer(), 'second':=integer(), 'std_offset':=integer(), 'time_zone':=binary(), 'utc_offset':=integer(), 'year':=integer(), 'zone_abbr':=binary()},integer()}
```
I do assume, that it is not better with the other libraries.
5 Likes