# Dialyzer error when checking Mix task

**URL:** <https://forum.elixirforum.com/t/dialyzer-error-when-checking-mix-task/53105>\
**Category:** Questions\
**Tags:** mix, dialyzer\
**Created:** [January 11, 2023, 9:54am UTC](https://forum.elixirforum.com/t/dialyzer-error-when-checking-mix-task/53105 "2023-01-11T09:54:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ijdickinson](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/ijdickinson/32/26881_2.png) [@ijdickinson](https://forum.elixirforum.com/u/ijdickinson)\
**Post date:** [January 11, 2023, 9:54am UTC](https://forum.elixirforum.com/t/dialyzer-error-when-checking-mix-task/53105/1 "2023-01-11T09:54:23Z")

</div>

I have a Mix task that extracts the version number of the project (for use in a build pipeline):

```elixir
defmodule Mix.Tasks.VersionNumber do
  @moduledoc "Mix task to print the current version number to stdout"
  use Mix.Task

  @shortdoc "Print the current application version number"
  def run(_) do
    MyApp.MixProject.project |> Keyword.fetch!(:version) |> IO.puts
  end
end

```

This all works fine. However, when I run `mix dialyzer` on my project, I get an error:

```elixir
$ mix dialyzer
Compiling 1 file (.ex)
Finding suitable PLTs
Checking PLT...
[:asn1, :castore, :certifi, :compiler, :connection, :cowboy, :cowboy_telemetry, :cowlib, 
:crypto, :dart_sass, :db_connection, :decimal, :ecto, :ecto_sql, :eex, :elixir, :esbuild, 
:expo, :file_system, :finch, :geo, :geo_postgis, :gettext, :hackney, :heroicons, :hpax, 
:httpoison, :idna, :jason, :kernel, :logger, :metrics, :mime, :mimerl, :mint, :mix, 
:nimble_options, :nimble_pool, :parse_trans, :phoenix, :phoenix_copy, :phoenix_ecto, 
:phoenix_html, :phoenix_live_dashboard, :phoenix_live_reload, :phoenix_live_view, 
:phoenix_pubsub, :phoenix_template, :plug, :plug_cowboy, ...]
PLT is up to date!
No :ignore_warnings opt specified in mix.exs and default does not exist.

Starting Dialyzer
[
  check_plt: false,
  init_plt: '/home/ian/projects/verna/myapp/_build/dev/dialyxir_erlang-25.1.2_elixir-1.14.2_deps-dev.plt',
  files: ['/home/ian/projects/verna/myapp/_build/dev/lib/myapp/ebin/Elixir.MyApp.LocationSearch.SearchResult.beam',
   '/home/ian/projects/verna/myapp/_build/dev/lib/myapp/ebin/Elixir.MyApp.beam',
   '/home/ian/projects/verna/myapp/_build/dev/lib/myapp/ebin/Elixir.MyApp.Application.beam',
   '/home/ian/projects/verna/myapp/_build/dev/lib/myapp/ebin/Elixir.MyApp.ReferenceData.LandRegistry.beam',
   '/home/ian/projects/verna/myapp/_build/dev/lib/myapp/ebin/Elixir.MyApp.Gettext.beam',
   ...],
  warnings: [:unknown]
]
Total errors: 1, Skipped: 0, Unnecessary Skips: 0
done in 0m4.56s
lib/mix/tasks/version_number.ex:7:unknown_function
Function MyApp.MixProject.project/0 does not exist.
________________________________________________________________________________
done (warnings were emitted)
Halting VM with exit status 2

```

At a guess, the problem is maybe related to `project/0` being defined in an `.exs` file rather than `.ex`? Is there a way to either ignore the mix task in the Dialyzer analysis, or, better, help it to find the definition of `project/0`?

---

<div class="post-metadata">

**Author:** ![Billzabob](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/billzabob/32/24061_2.png) [@Billzabob](https://forum.elixirforum.com/u/Billzabob)\
**Post date:** [April 19, 2023, 6:30pm UTC](https://forum.elixirforum.com/t/dialyzer-error-when-checking-mix-task/53105/2 "2023-04-19T18:30:18Z")

</div>

I’m having the same problem, did you ever find a solution?

---

<div class="post-metadata">

**Author:** ![ijdickinson](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/ijdickinson/32/26881_2.png) [@ijdickinson](https://forum.elixirforum.com/u/ijdickinson)\
**Post date:** [April 19, 2023, 7:45pm UTC](https://forum.elixirforum.com/t/dialyzer-error-when-checking-mix-task/53105/3 "2023-04-19T19:45:48Z")

</div>

We switched approach, so we dropped this task from our `project.exs`.

However, we did find ourselves having to ignore some other Dialyzer errors. The pattern for that is to create a `./.dialyzer-ignore.exs` file, using the pattern:

```elixir
[
{path, error},
]

```

So in theory, this should work:

```elixir
# .dialyzer-ignore.exs
[
{"./project.exs", :unknown_function}
]

```

But I’ve not tested it, so ymmv.

Good luck!  
Ian

---

<div class="post-metadata">

**Author:** ![al2o3cr](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/al2o3cr/32/3457_2.png) [@al2o3cr](https://forum.elixirforum.com/u/al2o3cr)\
**Post date:** [April 19, 2023, 11:01pm UTC](https://forum.elixirforum.com/t/dialyzer-error-when-checking-mix-task/53105/4 "2023-04-19T23:01:45Z")

</div>

Dialyzer depends on the compiler, so it’s definitely not going to see modules defined in `.exs` files.

That file will be loaded by Mix at runtime before running the task, so it doesn’t actually fail.

A better approach might be to use the built-in Mix machinery, specifically [`Mix.Project.config/0`](https://hexdocs.pm/mix/Mix.Project.html#config/0):

```elixir
defmodule Mix.Tasks.VersionNumber do
  @moduledoc "Mix task to print the current version number to stdout"
  use Mix.Task

  @shortdoc "Print the current application version number"
  def run(_) do
    Mix.Project.config() |> Keyword.fetch!(:version) |> IO.puts
  end
end

```

---

<div class="post-metadata">

**Author:** ![kenny-evitt](https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/k/e47774/32.png) [@kenny-evitt](https://forum.elixirforum.com/u/kenny-evitt)\
**Post date:** [October 24, 2024, 8:42pm UTC](https://forum.elixirforum.com/t/dialyzer-error-when-checking-mix-task/53105/5 "2024-10-24T20:42:49Z")

</div>

[This answer](https://stackoverflow.com/a/51218081/173497) on the following Stack Overflow question seems to have worked to fix similar errors for one of my own projects:

- [elixir - How to fix Dialyzer “Callback info about the ‘…’ behaviour is not available” error for new Mix.Tasks - Stack Overflow](https://stackoverflow.com/questions/51208388/how-to-fix-dialyzer-callback-info-about-the-behaviour-is-not-available)

The answer states that you can add the following to (the return value of) the `project/0` function in your project Mix module file (i.e. `mix.exs`) – or add `:mix` to the list if the key-value pair already exists:

```elixir
      dialyzer: [plt_add_apps: [:mix]]

```

Example `project/0` function:

```elixir
  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

```
