# Dialyzer Issues in Elixir Libraries

**URL:** <https://forum.elixirforum.com/t/dialyzer-issues-in-elixir-libraries/60608>\
**Category:** Questions\
**Tags:** dialyzer, dialyxir, hex-packages\
**Created:** [December 28, 2023, 3:27am UTC](https://forum.elixirforum.com/t/dialyzer-issues-in-elixir-libraries/60608 "2023-12-28T03:27:17Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![geoffrey](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/geoffrey/32/23987_2.png) [@geoffrey](https://forum.elixirforum.com/u/geoffrey)\
**Post date:** [December 28, 2023, 3:27am UTC](https://forum.elixirforum.com/t/dialyzer-issues-in-elixir-libraries/60608/1 "2023-12-28T03:27:17Z")

</div>

I am currently facing challenges with the Dialyzer tool while working on two Elixir libraries:

1. **AnyHttp Library:** This library offers a unified interface for various HTTP clients, allowing for flexibility in client selection. [AnyHttp Github](https://github.com/GRoguelon/any_http)

2. **ElasticsearchEx Library:** Overview: A client designed for Elasticsearch utilizing the `AnyHttp` library. [ElasticsearchEx Github](https://github.com/CoreCareinc/elasticsearch_ex)

**Issue Overview:**  
During the Dialyzer analysis of the `ElasticsearchEx` library, I encountered a complex error involving the `AnyHttp` library. The error includes references to `unknown_function` and `unknown_type` and presents an unusual issue regarding missing beam files. A snippet of the error message:

```plaintext
Could not get Core Erlang code for: elasticsearch_ex/_build/dev/lib/any_http/ebin/Elixir.AnyHttp.beam

```

> **Example of Dialyzer run**
>
> ```elixir
> Finding suitable PLTs
> Checking PLT...
> [:any_http, :asn1, :benchee, :compiler, :crypto, :deep_merge, :elasticsearch_ex, :elixir, :inets, :jason, :kernel, :logger, :public_key, :ssl, :ssl_verify_fun, :statistex, :stdlib, :tls_certificate_check]
> Looking up modules in dialyzer.plt
> Looking up modules in dialyxir_erlang-24.3.4.14_elixir-1.13.4.plt
> Finding applications for dialyxir_erlang-24.3.4.14_elixir-1.13.4.plt
> Finding modules for dialyxir_erlang-24.3.4.14_elixir-1.13.4.plt
> Checking 449 modules in dialyxir_erlang-24.3.4.14_elixir-1.13.4.plt
> Finding applications for dialyzer.plt
> Finding modules for dialyzer.plt
> Copying dialyxir_erlang-24.3.4.14_elixir-1.13.4.plt to dialyzer.plt
> Looking up modules in dialyzer.plt
> Checking 449 modules in dialyzer.plt
> Adding 324 modules to dialyzer.plt
> :dialyzer.run error: Analysis failed with error:
> Could not scan the following file(s):
> Could not get Core Erlang code for: elasticsearch_ex/_build/dev/lib/any_http/ebin/Elixir.Inspect.AnyHttp.Error.beam
> Could not get Core Erlang code for: elasticsearch_ex/_build/dev/lib/any_http/ebin/Elixir.AnyHttp.beam
> Could not get Core Erlang code for: elasticsearch_ex/_build/dev/lib/any_http/ebin/Elixir.AnyHttp.Utils.beam
> Could not get Core Erlang code for: elasticsearch_ex/_build/dev/lib/any_http/ebin/Elixir.AnyHttp.Response.beam
> Could not get Core Erlang code for: elasticsearch_ex/_build/dev/lib/any_http/ebin/Elixir.AnyHttp.Error.beam
> Could not get Core Erlang code for: elasticsearch_ex/_build/dev/lib/any_http/ebin/Elixir.AnyHttp.Client.beam
> Could not get Core Erlang code for: elasticsearch_ex/_build/dev/lib/any_http/ebin/Elixir.AnyHttp.Adapters.Httpc.beam
> 
> Last messages in the log cache:
> Reading files and computing callgraph...
> done in 0m3.66s
> No :ignore_warnings opt specified in mix.exs. Using default: .dialyzer_ignore.exs.
> 
> Starting Dialyzer
> [
> check_plt: false,
> init_plt: 'elasticsearch_ex/priv/plts/dialyzer.plt',
> files: ['elasticsearch_ex/_build/dev/lib/elasticsearch_ex/ebin/Elixir.ElasticsearchEx.Api.Document.beam',
> 'elasticsearch_ex/_build/dev/lib/elasticsearch_ex/ebin/Elixir.ElasticsearchEx.Api.Search.beam',
> 'elasticsearch_ex/_build/dev/lib/elasticsearch_ex/ebin/Elixir.ElasticsearchEx.Api.Utils.beam',
> 'elasticsearch_ex/_build/dev/lib/elasticsearch_ex/ebin/Elixir.ElasticsearchEx.Application.beam',
> 'elasticsearch_ex/_build/dev/lib/elasticsearch_ex/ebin/Elixir.ElasticsearchEx.Client.beam',
> ...],
> warnings: [:unknown]
> ]
> Total errors: 6, Skipped: 0, Unnecessary Skips: 0
> done in 0m0.35s
> lib/elasticsearch_ex/client.ex:27:unknown_function
> Function AnyHttp.request/5 does not exist.
> ________________________________________________________________________________
> lib/elasticsearch_ex/client.ex:82:unknown_function
> Function Jason.decode!/1 does not exist.
> ________________________________________________________________________________
> lib/elasticsearch_ex/client.ex:140:unknown_function
> Function Jason.encode!/1 does not exist.
> ________________________________________________________________________________
> lib/elasticsearch_ex/ndjson.ex:24:unknown_function
> Function Jason.encode!/1 does not exist.
> ________________________________________________________________________________
> lib/elasticsearch_ex/ndjson.ex:41:unknown_function
> Function Jason.decode!/1 does not exist.
> ________________________________________________________________________________
> lib/elasticsearch_ex/error.ex:22:unknown_type
> Unknown type: AnyHttp.Response.t/0.
> ________________________________________________________________________________
> done (warnings were emitted)
> Halting VM with exit status 2
> 
> ```

Despite verifying the presence of the beam files in the specified location, I continue to encounter this issue. Additionally, when `ElasticsearchEx` is utilized as a dependency in any application and Dialyzer is executed, an extensive number of errors, exceeding 1,000, are generated. These errors appear to be related to missing dependencies such as `elixir` and `mix` and much more.

> **Partial extract of Dialyzer errors**
>
> ```elixir
> ________________________________________________________________________________
> Callback info about the Oban.Pro.Worker behaviour is not available.
> ________________________________________________________________________________
> Callback info about the Oban.Worker behaviour is not available.
> ________________________________________________________________________________
> Function Oban.Pro.Worker.init_stage!/2 does not exist.
> ________________________________________________________________________________
> Function Oban.Pro.Worker.fetch_recorded/1 does not exist.
> ________________________________________________________________________________
> Function Ecto.Changeset.add_error/3 does not exist.
> ________________________________________________________________________________
> Function Oban.Job.new/2 does not exist.
> ________________________________________________________________________________
> Function Oban.Pro.Worker.before_new/2 does not exist.
> ________________________________________________________________________________
> Function Oban.Worker.merge_opts/2 does not exist.
> ________________________________________________________________________________
> Function Oban.Pro.Worker.process/3 does not exist.
> ________________________________________________________________________________
> Function Logger. __do_log__ /4 does not exist.
> ________________________________________________________________________________
> Function Logger. __should_log__ /2 does not exist.
> ________________________________________________________________________________
> Function Logger. __do_log__ /4 does not exist.
> ________________________________________________________________________________
> Function Logger. __should_log__ /2 does not exist.
> ________________________________________________________________________________
> 
> ```

**Request for Assistance:**  
Given the complexity of the error messages and my attempts to resolve the issue using different Elixir versions (1.13 to 1.16) without success, I would greatly appreciate any insights or guidance you might have on resolving this issue.

Thank you by advance.

---

<div class="post-metadata">

**Author:** ![al2o3cr](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/al2o3cr/32/3457_2.png) [@al2o3cr](https://forum.elixirforum.com/u/al2o3cr)\
**Post date:** [December 28, 2023, 11:51am UTC](https://forum.elixirforum.com/t/dialyzer-issues-in-elixir-libraries/60608/2 "2023-12-28T11:51:11Z")

</div>

> [@geoffrey](#):
>
> During the Dialyzer analysis of the `ElasticsearchEx` library,

Can you provide some more detail about the steps you took? The messages here suggest that Dialyzer’s metadata is severely confused, but it’s hard to guess how that could have happened.

---

<div class="post-metadata">

**Author:** ![geoffrey](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/geoffrey/32/23987_2.png) [@geoffrey](https://forum.elixirforum.com/u/geoffrey)\
**Post date:** [December 28, 2023, 5:57pm UTC](https://forum.elixirforum.com/t/dialyzer-issues-in-elixir-libraries/60608/3 "2023-12-28T17:57:25Z")

</div>

Hi,

Thank you @al2o3cr for you reply.

I’ve created a branch on `ElasticsearchEx` with the content of `.dialyzer_ignore.exs` disabled. You can see the Dialyzer run [here](https://github.com/CoreCareinc/elasticsearch_ex/actions/runs/7350027663/job/20010982762?pr=27).

```elixir
Warning: Function AnyHttp.request/5 does not exist.
Warning: Function Jason.decode!/1 does not exist.
Warning: Function Jason.encode!/1 does not exist.
Warning: Function Jason.encode!/1 does not exist.
Warning: Function Jason.decode!/1 does not exist.
Warning: Unknown type: AnyHttp.Response.t/0.

```

If you need an application with `ElasticsearchEx` as dependency, I can provide it later today.

Let me know if you need anything else.

---

<div class="post-metadata">

**Author:** ![al2o3cr](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/al2o3cr/32/3457_2.png) [@al2o3cr](https://forum.elixirforum.com/u/al2o3cr)\
**Post date:** [December 28, 2023, 7:15pm UTC](https://forum.elixirforum.com/t/dialyzer-issues-in-elixir-libraries/60608/4 "2023-12-28T19:15:40Z")

</div>

The root cause appears to be one line in [AnyHttp’s configuration](https://github.com/GRoguelon/any_http/blob/main/mix.exs#L10):

```elixir
elixirc_options: [debug_info: Mix.env() == :dev],

```

This setting has caused exactly the behavior you observed (“Could not get Core Erlang code for …etc…”) in other projects:

> [@Dialyzer "Could not get Core Erlang code for"](https://forum.elixirforum.com/t/dialyzer-could-not-get-core-erlang-code-for/56730/11):
>
> When a dependency is installed by mix, Mix.env is normally :prod - you can change that with the [env option](https://hexdocs.pm/mix/main/Mix.Tasks.Deps.html#module-dependency-definition-options) That causes polyn’s mix.exs to omit the metadata (line 14): [https://github.com/SpiffInc/polyn/blob/7565047566106f02ab289ca0e4a681e257701807/polyn\_elixir\_client/mix.exs#L14](https://github.com/SpiffInc/polyn/blob/7565047566106f02ab289ca0e4a681e257701807/polyn_elixir_client/mix.exs#L14)

I tested this locally with the `chore/broken-dialyzer` branch:

- Running `mix dialyzer` on the code as-is fails with the previously-discussed errors about missing functions.
- Commenting out the `elixirc_options` line in AnyHttp’s `mix.exs` and rebuilding from scratch (after removing `_build` and `priv/plts`) gives a successful result with no errors.

---

<div class="post-metadata">

**Author:** ![geoffrey](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/geoffrey/32/23987_2.png) [@geoffrey](https://forum.elixirforum.com/u/geoffrey)\
**Post date:** [December 28, 2023, 8:46pm UTC](https://forum.elixirforum.com/t/dialyzer-issues-in-elixir-libraries/60608/5 "2023-12-28T20:46:31Z")

</div>

It worked!

I spent hours searching for the cause without. Actually, I thought that option was needed as it’s mentioned in some places remotely related to my error message, For instance, I found a [thread](https://forum.elixirforum.com/t/dialyzer-could-not-get-core-erlang-code-for/56730/11) where you actually provided the solution.

Thank you so much for replies and the prompt resolution.

---

<div class="post-metadata">

**Author:** ![zetetic](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/zetetic/32/37926_2.png) [@zetetic](https://forum.elixirforum.com/u/zetetic)\
**Post date:** [April 19, 2025, 2:34am UTC](https://forum.elixirforum.com/t/dialyzer-issues-in-elixir-libraries/60608/6 "2025-04-19T02:34:17Z")

</div>

FWIW adding `debug_info: [Mix.env() == :dev]` to `elixirc_options` also broke test coverage reporting in my project, e.g.

`mix test --cover`

produced a report showing no modules tested and 100% coverage.

```elixir
Generating cover results ...

Percentage | Module
-----------|--------------------------
-----------|--------------------------
   100.00% | Total

```

Took quite a while to find out that was the offending line. No idea what is going on.

---

<div class="post-metadata">

**Author:** ![christhekeele](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/christhekeele/32/1039_2.png) [@christhekeele](https://forum.elixirforum.com/u/christhekeele)\
**Post date:** [April 20, 2025, 8:41am UTC](https://forum.elixirforum.com/t/dialyzer-issues-in-elixir-libraries/60608/7 "2025-04-20T08:41:31Z")

</div>

> [@zetetic](#):
>
> No idea what is going on.

To clarify: most `mix` commands run with `Mix.env() == :dev`. However, when running `mix test`, you will find that `Mix.env() == :test`.

So, setting `debug_info: [Mix.env() == :dev]` will disable debug info when running `mix test --cover`, which is exactly what’s needed to produce test coverage results.

Instead, try `debug_info: [Mix.env() != :prod]` (where `:prod` is the default environment for `mix release`s) to ensure all lower environments that are not performance-sensitive get the extra telemetry on the BEAM VM to generate meaningful debug info.
