brainlid

brainlid

Blog Post: Adding Dialyzer without the Pain

Dialyzer is a tool that you’ve probably heard about in the Elixir community. You may have even used it. However, adding Dialyzer to an existing project can feel overwhelming when you see the wall of red and have 100s of errors. Hitting that resistance can turn people right around, running for the door. Noah Betzen shows us how adding Dialyzer doesn’t have to be scary. He walks us through the process on several existing public Elixir projects. He shares some tips and tricks that let us keep our productivity without getting overwhelmed.

Most Liked

jhogberg

jhogberg

Erlang Core Team

but it’s worth mentioning that ignoring new errors is completely valid as well.

It’s also worth mentioning that dialyzer will not analyze beyond errors because that state is absurd and cannot be reasoned about: ignoring the error merely suppresses the message. This can suppress other errors or magically bring new and incredibly difficult ones into existence.

Warnings like those for constructing “improper” lists are safe to ignore, but I don’t recommend ignoring errors. By all means, feel free to tackle the problems one at a time, but shoving them under the rug by placing them in an ignore-file can make other errors needlessly difficult to diagnose. :confused:

Nezteb

Nezteb

Let’s say we have a file that it’s ignored. Now, some code is added to that file and that new code has an error. Is there a way to have dialyzer warn about this?

One thing you can do is:

# .dialyzer_ignore.exs
[
  {"lib/something.ex", :no_return},
  {"lib/something.ex", :call},
]

Now, if you introduce new errors to lib/something.ex, as long as it isn’t a :no_return or :call error, it will still get caught. However, if you do add a new :no_return error to the file, it will get ignored unfortunately.

Another option is to use regex patterns (which I’ve not experimented with much), like so:

# .dialyzer_ignore.exs
[
  ~r/my_file\.ex.*my_function.*no local return/
]

With this, you could refine the ignored error to a specific function/error combination.

However, I created a PR to add a more strict ignore file format, and it’s been merged. It should come out in the next release of dialyxir.

Also, one helpful method to partially address the weaknesses of the ignore method that @jhogberg pointed out is:

  1. Delete all ignored lines from the .dialyzer_ignore.exs file.
  2. Run mix dialyzer again.
  3. Fix whatever errors you can (or are willing to). Maybe isolate your quest to a single file/module at a time.
  4. Regenerate an ignore file and add those lines to the ignore file again. This should hopefully now be a smaller file than it was previously.
kazlu

kazlu

I’ve been in discussions with my team about adding dialyzer to our codebase. I like the approach you outline in the article, however I do have a question. Let’s say we have a file that it’s ignored. Now, some code is added to that file and that new code has an error. Is there a way to have dialyzer warn about this? AFAICT we only have 2 options:

  1. Ignore specific lines. This seems like a maintenance nightmare as line numbers will have to be kept in sync.
  2. Ignore specific error types. This kind of works, but would break if the error is the same type as a previously ignored error.

Once we get to 0 errors, this will solve itself out, so I’m not super concerned, but I just wanted to get some input from the experts.

Thank you!

Where Next?

Popular in Blog Posts Top

luckywatcher
Hey all! I just started a blog focused on web development in Elixir. I wrote my first article and thought I’d post it here for the whole...
New
ErlangSolutions
An infographic that compares Erlang, Elixir, and Go's strengths in the respect to the programming languages' concurrency, reliability, sc...
New
fredwu
Hi folks, I wrote a blog post the other day on how I built my MVP in 3 months whilst having a day job, using Elixir/Phoenix/LiveView. Th...
New
New
New
JEG2
I’m closing out, for now, my series on questions at the heart of development with an analysis of when we need more abstraction. For exam...
New
stryrckt
Support for AlpineJS in LiveView was added in 0.13.3 and it works fabulously. I just wrote a blog article about it and plan another one s...
New
gaggle
This post explores different ways to do test automation in Elixir, focusing on how to handle dependency injection — covering patterns, li...
New
psantos
Just wrote a new blog post about how to deploy a Phoenix app using Kamal 2. Check it out and let me know what do you think:
New
lawik
One of the Erlang ecosystem’s spiciest nerd snipes are hot code updates. Because it can do it. In ways that almost no other runtime can.
New

Other popular topics Top

SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call th...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 45766 226
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 42633 214
New
AstonJ
by Lance Halvorsen Elixir and Phoenix are generating tremendous excitement as an unbeatable platform for building modern web application...
460 27162 124
New

We're in Beta

About us Mission Statement