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

brainlid
There is a new community resource available on writing “Safe Ecto Migrations”. When we get a migration wrong, it can lock up your product...
New
blackode
https://medium.com/blackode This article comprises of two biggest changes of ExUnit. Arguments in the failure report Running mix tes...
New
Paradox
Testing is an important part of any modern piece of software. But writing tests can quickly become an exercise in frustration, with tons ...
New
ErlangSolutions
Hey all, it’s Erlang Solutions. We released loads of Elixir content from our senior developers last week in celebration of ElixirConf US...
New
danschultzer
How to set up the Content Security Policy header with Phoenix LiveView and support inline styles and scripts with CSP nonces.
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
ragamuf
Does the world need another How to create a blog article? Maybe not. But then again, creating something out of nothing is what we love....
New
brainlid
You are storing some Phoenix LiveView state in the browser. You want to retrieve that saved state as early as possible to improve the use...
New
bram209
Hello everyone, I just published my first blog post ever. I am learning Elixir, OTP & Phoenix and wanted to start a blog for a while...
New
brainlid
Jason Stiebs shows a couple ways for a LiveView to make it easy for users to click and copy an important value to their clipboard. He sho...
New

Other popular topics Top

senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
Nvim
Anybody knows a comprehensive comparison of Django and Phoenix, thanks for the help. Where are they similar? Where do they differ the m...
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
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
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New

We're in Beta

About us Mission Statement