Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unmatched returns of Logger

The static analyser dialyzer (I use it via dialyxir) reports all usage of Logger (Logger.info "blah") as an unmatched return:

Expression produces a value of type 'ok' | {'error',_}, but this value is unmatched

I could write :ok  = Logger.info "blah" but obviously, it's cumbersome. I could also configure dialyser with -Wno_unmatched_returns to ignore all theses warnings. However, I find them very informative and don't want to ignore them.

The documentation of dialyzer says that we can use module attributes to deactivate warnings on a per-module basis, but I fail to see if it's only possible to put this information in Elixir source files.

Is there a way to configure Dialyzer to ignore such warnings, but only for Logger?

like image 963
Alexandre Hamez Avatar asked Oct 18 '22 12:10

Alexandre Hamez


1 Answers

There's documentation of the @dialyzer attribute here. You will need to search down the page a bit to find it.

In this particular case, I believe the following module attribute:

@dialyzer {:no_return, your_function_name: 1}

Should give you what you want. Just put it at the top of each module where you're using Logger like so:

defmodule MyLogging do
 @dialyzer {:no_return, your_function_name: 1}
 .
 .
 .

Note that it appears that you can only shut off the warnings for the functions in the current module. That is, it doesn't seem to be possible to shut off warnings for functions in a different module (e. g. Logger.info: 1).

like image 155
Onorio Catenacci Avatar answered Nov 04 '22 22:11

Onorio Catenacci