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

SmartLogic
Season four of the Elixir Wizards podcast launches today! This season we’re focused on system and application architecture. We’ll be doin...
New
brainlid
Building a LiveView powered chat app is easier than ever when using Streams! Sophie DeBenedetto shows us how in this article. She createa...
New
blackode
https://medium.com/blackode This article comprises of two biggest changes of ExUnit. Arguments in the failure report Running mix tes...
New
brainlid
Elixir has a built-in Zip library that comes with OTP. This post explores how to use the zip module and asks the important question: “Is ...
New
rrrene
In this series, we take a look at the different ways to organize, structure and execute a good “flow” in our Elixir programs. The latest...
New
ryotsu
How does a torrent client download huge files from the internet with just a .torrent file? In this post we’ll explore the BitTorrent prot...
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
hauleth
I wanted to write down some of the main guides I use when writing Elixir tests, so I have summarised them in blogpost. Furthermore, I th...
New
PragTob
I ran into an interesting problem recently where simple concurrency on the BEAM via Task.async made my application a lot slower and a lot...
New
bemesa21
Add drag-and-drop functionality to your Phoenix LiveView app with SortableJS and LiveView Hooks! This posts shows you how to create an in...
New

Other popular topics Top

Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 52341 488
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
klo
Got a question about when to concat vs. prepending items to list then reversing to achieve appending. So i know lists boil down to [1 | ...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 126479 1222
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New

Latest on Elixir Forum

We're in Beta

About us Mission Statement