Fl4m3Ph03n1x

Fl4m3Ph03n1x

Dialyzer giving warnings that make no sense

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?

Marked As Solved

NobbZ

NobbZ

Its already reported and closed:

I’m not sure though, if the fix is in the 1.7 branch or only for 1.8.

Also Liked

NobbZ

NobbZ

Thats hard to tell from this perspective, but probably something in prometheus is faulty?

In general it makes totally sense that tuple_size/1 called with an exception as argument would not suceed. Problem is though, I can not find any reference to tuple_size/1 in either prometheus_plugs, nor prometheus_ex.

So this problem might be burried even deeper.


edit

Can’t even find tuple_size it in the underlying erlang library. I’m trying to dig into this locally. Dialyzer is building its PLT right now…

Fl4m3Ph03n1x

Fl4m3Ph03n1x

@NobbZ Just to make it clear, I truly appreciate all the help you are giving. Without you this forum wouldn’t be what it is today.

Thank you.


On a separate note, if this is an issue with Prometheus, what are the options?

  1. make a PR to fix it?
  2. ask dialyzer to ignore prometheus_ex ? ( not sure if even possible )
NobbZ

NobbZ

Spoiler warning… I sshd into my system at home which runs 1.7/21. It triggers the same errors as you report. Ill have to play a bit with versions to learn more…

NobbZ

NobbZ

This seems to happen in the expansion of Prometheus.Error.with_prometheus_error/1, as the same messages appear when I run dialyzer in the prometheus_ex code base at places where that macro is used:

lib/prometheus/format/protobuf.ex:13: Guard test tuple_size(__@5::#{'__exception__':='true', '__struct__' :=_, _=>_}) can never succeed
lib/prometheus/format/protobuf.ex:21: Guard test tuple_size(__@5::#{'__exception__':='true', '__struct__' :=_, _=>_}) can never succeed
lib/prometheus/format/text.ex:26: Guard test tuple_size(__@5::#{'__exception__':='true', '__struct__':=_, _=>_}) can never succeed
lib/prometheus/format/text.ex:34: Guard test tuple_size(__@5::#{'__exception__':='true', '__struct__':=_, _=>_}) can never succeed  

The output is from dialyxir ~> 0.5.0, as that is the specified dependency of prometheus_ex.

As in that macro some testing about the availability of __STACKTRACE__ is done, I have to assume this is due changes in OTP 21 (or has it been in 20?) and exception handling. This is definitifely something that needs to be reported at prometheus.ex.

NobbZ

NobbZ

Its even worse and I will prepare a bug report to elixir, as I can reproduce the issue with the following minimal module:

defmodule Foobar do
  def hello do
    try do
      IO.puts("foo")
    rescue
      e in ErlangError ->
        :error
    end
  end
end

Where Next?

Popular in Questions Top

JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: https://hexdocs.pm/ecto/Ecto.Schema.html#module-...
New
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
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
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
New
LegitStack
I’m trying to make a websocket server in Phoenix or raw Elixir. I heard about gun, I think I could use cowboy, but since I’m not that sma...
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New

Other popular topics Top

shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
977 41022 311
New
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
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 49522 488
New
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
Nvim
Elixir appears to be a superior language to Python. I don’t see any advantage of Python over Elixir. Are there any?
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New

We're in Beta

About us Mission Statement