Unrivaled Logger Profit

The static dialyzer analyzer (I use it through dialyxir ) reports using Logger ( Logger.info "blah" ) as an unrivaled return:

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

I could write :ok = Logger.info "blah" , but obviously this is cumbersome. I could also configure dialyser with -Wno_unmatched_returns to ignore all of these warnings. However, I find them very informative and do not want to ignore them.

the documentation on dialyzer says that we can use module attributes to deactivate alerts for each module, but I don’t see, you can only put this information in the Elixir source files.

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

+5
source share
1 answer

The @dialyzer attribute documentation is here . You will need to search the page a bit to find it.

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

 @dialyzer {:no_return, your_function_name: 1} 

Gotta give you what you want. Just put it at the top of each module where you use Logger like this:

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

Please note that you can only disable warnings for functions in the current module. That is, it is apparently impossible to disable warnings for functions in another module (for example, Logger.info: 1 ).

+3
source

Source: https://habr.com/ru/post/1246390/


All Articles