tino415

tino415

Dialyzer cachex unable to solve types

Hello all,

I’m triing to integrate dialyzer/dialyxer into one project that is using cachex, but dialyzer keeps reporting some veird error with Cachex.start_link/2 function. I managed to destille minimal example:

defmodule Test do
  def hello do
    {:ok, _pid} = Cachex.start_link(__MODULE__, stats: true)
  end
end

Dialyzer is complaining that

lib/test.ex:3:pattern_match
The pattern can never match the type.

Pattern:
{:ok, __pid}

Type:
:error | :ok | {:error, atom() | {:already_started, pid() | {_, _}}}

But when I tri to run function in iex, it returns {:ok, pid()}, also when I look at the code, typescpecs seems right and code also, so, how did dialyzer come up with return type :error | :ok | {:error, atom() | {:already_started, pid() | {_, _}}}? The code for Cachex.start_link/2 looks like this:

  @spec start_link(atom | Keyword.t) :: { atom, pid }
  def start_link(options) when is_list(options) do
    with { :ok,  name } <- Keyword.fetch(options, :name),
         { :ok,  true } <- ensure_started(),
         { :ok,  true } <- ensure_unused(name),
         { :ok, cache } <- setup_env(name, options),
         { :ok,   pid }  = Supervisor.start_link(__MODULE__, cache, [ name: name ]),
         { :ok,  link }  = Informant.link(cache),
                ^link   <- Overseer.update(name, link),
     do: { :ok,   pid }
  end
  def start_link(name) when not is_atom(name),
   do: error(:invalid_name)
  def start_link(name),
    do: start_link(name: name)

  @doc false
  @spec start_link(atom(), Keyword.t) :: { atom(), pid() }
  def start_link(name, options),
    do: start_link([name: name] ++ options)

Anybody have experience with similar problem and how to solve it?

Marked As Solved

michallepicki

michallepicki

This seems to be a bug in specs in the sleeplocks library and should be fixed by Fix execute/2 spec by michallepicki · Pull Request #5 · whitfin/sleeplocks · GitHub

Last Post!

michallepicki

michallepicki

It’s possible that Cachex also has wrong specs, at least I think in many modules types referenced from specs won’t be found by Dialyzer, e.g. here: cachex/lib/cachex/services/overseer.ex at main · whitfin/cachex · GitHub Spec is used but Supervisor.Spec is aliased, not Cachex.Spec. But I may be wrong, and in that case Dialyzer is probably smart enough to ignore the spec.

Overall this is a common problem through the Elixir ecosystem, almost none of the libraries are running Dialyzer on the CI so specs just get outdated or invalid. I try to maintain Elixir itself working somehow with Dialyzer by running a check on it every day: GitHub - michallepicki/elixir-lang-dialyzer-runs: Daily Dialyzer checks on Elixir source code · GitHub but it won’t catch some issues because they may pop up when a function is called, not defined, and I am not analyzing Elixir test modules since they are .exs files.

Where Next?

Trending in Questions Top

lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
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
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" =&gt; #BSON.ObjectId&lt;58eb1a7a9ad169198c3dXXXX&gt;, "email" =&gt; ...
New
tj0
I’ve been following the steps here for the upgrade from 1.6 to 1.7 and it has gone relatively smoothly all the way till the phoenix_view ...
New
cgraham
Hi! What is currently the best library/method for parsing text and tabular data out of PDF files in Elixir or Erlang?
New
stefanchrobot
Hi, I need a way to handle data migrations in my application. I found an article by @wojtekmach about manual migrations: Automatic and ma...
New
stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
kip
Localize is the next generation localisation library for Elixir. Think of it as ex_cldr version 3.0. The first version will be released ...
New
webofbits
Squid Mesh is an open source workflow automation runtime for Elixir applications. It is aimed at Phoenix and OTP apps that want to defin...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
kip
In 2021 I started a new library called Tempo with the objective of modelling time as a set of intervals - not as instants. In 2022 I gave...
New

We're in Beta

About us Mission Statement