Background
I have recently started trying out dialyxir
. After playing around with a few pet projects I decided to up the game and try it into something more real.
Problem
However, dialyxir is giving me warnings that make no sense whatsoever. Thanks to the success algorithm dialyzer uses, I would expect it to not find every possible error which is fine, but giving me so many false positives ( which should be impossible ) is definitely something I was not expecting - it completely ruins the experience with noisy warnings that are useless.
Have a look on the following behaviour:
defmodule MyApp.Web.MetricsInstrumenter do
@moduledoc """
Adds HTTP related metrics for every request.
See used Prometheus.PlugPipelineInstrumenter module for details.
"""
use Prometheus.PlugPipelineInstrumenter
end
This created the following dialyxir warning:
lib/myapp/web/metrics_instrumenter.ex:6:guard_fail
Guard test:
tuple_size(_ :: Exception.t())
can never succeed.
This is mind blowing. This makes no sense whatsoever. There is literally only 1 line of code and that line doesn’t even have a when
clause.
Why am I getting this error?
Questions
I keep thinking this is a configuration problem. Somehow, I am not configuring the app correctly in the mix.exs
file while using Prometheus.
defmodule MyApp.MixProject do
@moduledoc false
use Mix.Project
def project do
[
app: :myaap,
version: "1.1.0",
elixir: "~> 1.7",
elixirc_paths: elixirc_paths(Mix.env()),
start_permanent: Mix.env() == :prod,
deps: deps()
]
end
def application do
[
extra_applications: [:logger],
mod: {MyApp.Application, []}
]
end
defp deps do
[
{ :plug, "~> 1.0" },
{ :prometheus_plugs, "~> 1.1.5" },
{ :prometheus_ex, "~> 3.0" },
{ :dialyxir, "~> 1.0.0-rc.4", only: [:dev], runtime: false }
]
end
defp elixirc_paths(:test), do: ["lib", "test/support"]
defp elixirc_paths(:dev), do: ["lib", "test/support"]
defp elixirc_paths(_), do: ["lib"]
end
But nothing I do works.
Why am I getting these non nonsensical errors?