geoffrey

geoffrey

Dialyzer Issues in Elixir Libraries

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

  2. ElasticsearchEx Library: Overview: A client designed for Elasticsearch utilizing the AnyHttp library. ElasticsearchEx Github

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:

Could not get Core Erlang code for: elasticsearch_ex/_build/dev/lib/any_http/ebin/Elixir.AnyHttp.beam
Example of Dialyzer run
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
________________________________________________________________________________
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.

Marked As Solved

al2o3cr

al2o3cr

The root cause appears to be one line in AnyHttp’s configuration:

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:

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.

Also Liked

christhekeele

christhekeele

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 releases) to ensure all lower environments that are not performance-sensitive get the extra telemetry on the BEAM VM to generate meaningful debug info.

Where Next?

Popular in Questions Top

stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
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
logicmason
Hi there, I'm working through my first release with elixir/phoenix. I've built a release with distillery and found that it crashes when I...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
Jim
As a follow up to my earlier question: I have the code compiling and running but not getting a successful login from the rest server. ...
New
gonzofish
I’m currently trying to understand how to join three tables using Ecto. All the examples I’ve seen use 2, so maybe I’m just missing somet...
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
idi527
I’ve been re-reading swift book again and noticed that multiline strings there don’t have a trailing line break, unlike in elixir iex(2)...
New

Other popular topics 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
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
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
Tee
can someone please explain to me how Enum.reduce works with maps
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 27727 240
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
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
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New

We're in Beta

About us Mission Statement