fmcgeough

fmcgeough

Another Dialyzer puzzle - 'Function will never be called'

I’m using the elixir-google-api/clients/sheets at main · googleapis/elixir-google-api · GitHub 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?

First 9 of 9 Posts Switch mode

dom

dom

“Function get_spreadsheet/1 will never be called” is just fallout from the real error. What does dialyzer say before that?

NobbZ

NobbZ

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.

fmcgeough

fmcgeough OP

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

NobbZ

Can you provide a minified project that produces similar warnings?

Or is the original projects source publicly available?

fmcgeough

fmcgeough OP

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.

fmcgeough

fmcgeough OP

Here’s a public repo that demos the issue. https://github.com/fmcgeough/google_sheet_dialyer

NobbZ

NobbZ

The PLT is building right now, I’ll take a look at it as my family gives me the time :wink:

OvermindDL1

OvermindDL1

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
NobbZ

NobbZ

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:

https://github.com/GoogleCloudPlatform/elixir-google-api/issues/73

— All posts loaded —

Where Next?

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
jonnycharles
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
spammy
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
silverdr
Using Phoenix.LiveView.TagEngine as an EEx.Engine is deprecated! To compile HEEx, use Phoenix.LiveView.TagEngine.compile/2 instead. Sta...
New
dli
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app? Looking for hints regarding: Addi...
New
bottlenecked
Hi all, I wanted to ask how the community is dealing with post-release steps. Today we have Ecto migrations, which make sure that the db...
New
michallepicki
I am using Oban and occasionally, shortly after a deployment, a handful of jobs can fail because of dependency on other parts of the syst...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
type1fool
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New
akoutmos
@hugobarauna and I (Alex Koutmos) have been hard at work on writing a book on Nerves that takes you from simply blinking LEDs to building...
New

We're in Beta

About us Mission Statement