Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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?

like image 455
prnsml Avatar asked Jul 06 '18 10:07

prnsml


People also ask

What does mix dialyzer do?

1.0) This task compiles the mix project, creates a PLT with dependencies if needed and runs dialyzer . Much of its behavior can be managed in configuration as described below.

What is dialyzer elixir?

Dialyzer is a static analysis tool for Erlang and other languages that compile to BEAM bytecode for the Erlang VM. It can analyze the BEAM files and provide warnings about problems in your code including type mismatches and other issues that are commonly detected by static language compilers.


Video Answer


1 Answers

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

like image 127
prnsml Avatar answered Nov 05 '22 07:11

prnsml