Compilation error in file - (ArgumentError) argument error (stdlib) :ets.lookup_element(:hackney_config, :mod_metrics, 2)

(Please note: Elixir Experience Level: Beginner)

iex -S mix
Erlang/OTP 21 [erts-10.2.4] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [hipe]

Compiling 2 files (.ex)

== Compilation error in file lib/pump.ex ==
** (ArgumentError) argument error
    (stdlib) :ets.lookup_element(:hackney_config, :mod_metrics, 2)
    /deps/hackney/src/hackney_metrics.erl:27: :hackney_metrics.get_engine/0
    /deps/hackney/src/hackney_connect.erl:78: :hackney_connect.create_connection/5
    /deps/hackney/src/hackney_connect.erl:47: :hackney_connect.connect/5
    /deps/hackney/src/hackney.erl:333: :hackney.request/5
    lib/httpoison/base.ex:793: HTTPoison.Base.request/6
    lib/httpoison.ex:128: HTTPoison.request!/5
    lib/pump.ex:4: (module)

What’s causing this error and what’s the solution?

What’s in the pump.ex around line 4 where the error is? :slight_smile:

defmodule Pump do
	#Get most actively traded pairs as often as possible from
	trading_activity = HTTPoison.get! ("")

	snapshot = Poison.decode! trading_activity.body, keys: :atoms

	#Exclude all pairs with volumeWAVES < 500

	volume_waves_greater_than_or_equal_to_500 = Enum.filter(, fn pairs -> >= 500.0 end)	

	#Send results to database.


Alright, I think HTTPoison may not be started with your application.

Can you show me your mix.exs file for the project (possibly covering the sensitive parts if needed?).

defmodule Arbit.MixProject do
  use Mix.Project

  def project do
      app: :arbit,
      version: "0.1.0",
      elixir: "~> 1.8",
      start_permanent: Mix.env() == :prod,
      deps: deps()

  def application do
      extra_applications: [:logger, :ecto, :postgrex, :hackney, :httpoison, :poison]

  defp deps do
    	{:httpoison, "~> 1.6"},
	{:poison, "~> 4.0"},
	{:postgrex, ">= 0.0.0"},
	{:ecto_sql, "~> 3.2.0"}

Is there any reason you do that request at compile time?

If you really want to do that, you need to Application.ensure_started/1 for applications you need runtime features off.

Also most of the apps you specified in :extra_applications don’t belong there as they have been inferred by mix anyway because they are in deps.

1 Like

Ah shoot I totally missed that. Yeah, that’s the reason, the applications like HTTpoison are not started at compile time. The whole code probably should be within some function.

1 Like

Apologies, I don’t follow. Please elaborate :slight_smile:

By using defmodule you are creating a module, its body will get evaluated at compile time to eventually become the modules functions and then gets stored to disk.

Those module and the functions within can then be used at runtime to produce values.

Elixirs compilation though can also call function in another module and use the result to produce code that creates functions, so thats what your current code looks like it’s eventually trying to do that.

I’m not sure though if you really get what I’m writing, as I’m not sure how to explain properly, also I’m on the bus crowded with people and I can’t properly think in such an environment…


Thanks for your patient and detailed explanation. I used it to rework the code as follows:

def get_trading_activity do

 		case HTTPoison.get("") do
			{:ok, _} ->
			results = HTTPoison.get!("")

			json_into_atoms = Poison.decode!(results.body, keys: :atoms)

		#Exclude all pairs with volumeWAVES < 500

			Enum.filter(, fn pairs -> >= 500.0 end)
			{:error, %HTTPoison.Error{reason: reason}} ->
			IO.inspect reason


Thanks again!