How to fix Dialyzer "Callback info about the '.....' behaviour is not available" error for new Mix.Tasks
Asked Answered
D

1

31

I created new Mix.Task in /lib/mix/tasks/start.ex for my project

defmodule Mix.Tasks.Start do
  use Mix.Task

  def run(_), do: IO.puts("Hello, World!")
end

Now, it could be run from console like this :
mix start

But I'm getting Dialyzer error, that Callback info about the 'Elixir.Mix.Task' behaviour is not available. What does it mean and how this could be fixed?

Diagram answered 6/7, 2018 at 10:29 Comment(1)
This could be the projects dialyzer settings missing some deps in the PLT, are you using mix dialyxer or directly configuring dialyzer? Can you post the project function from your mix.exs file, which carries the configuration.Fraternity
D
41

Looks like I didn't have Persistent Lookup Table (PLT) options added for dialyzer. In my case for 'Elixir.Mix.Task' behavior to be available for dialyzer I had to update mix.exs file and define for which modules dialyzer should create PLT.

  def project do
    [
      app: :some_app,
      version: "0.1.0",
      elixir: "~> 1.6",
      start_permanent: Mix.env() == :prod,
      deps: deps(),
      # Added following line
      dialyzer: [plt_add_apps: [:mix]]
    ]
  end

dialyzer is added through dialyxir in same mix.exs file like this

  defp deps do
    [
      {:dialyxir, "~> 0.5", only: [:dev], runtime: false}
    ]
  end

mix do deps.get, deps.compile
And your dialyzer should stop complaining:
mix dialyzer

Diagram answered 6/7, 2018 at 21:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.