I am receiving an error message regarding the access of an ets table “1st argument: the table identifier does not refer to an existing ETS table”. I am not trying to access an ets table. The very simple code segment is below
## program to fetch api prog from json place holder
defmodule Tst22api do
IO.gets "in Tst22api"
def fetch_user do
IO.puts("before HTTPoison")
IO.gets "in fetch_user"
{:ok, response} = HTTPoison.get("https://jsonplaceholder.typicode.com/users/1")
IO.inspect(response)
IO.puts("after HTTPoison")
response
end
end
Tst22api.fetch_user()
I am receiving the error message upon the execution of the line of code below.
{:ok, response} = HTTPoison.get("https://jsonplaceholder.typicode.com/users/1")
If I type this line of code in iex following the project load “iex -S mix” (minus the tst22api.ex module) the json API is fetched and displayed. If i include the tst22api.ex module in the iex -S mix (project load) the error message above is encountered. The {:ok, response} tuple in the HTTPoison.get command is somehow triggering the ets.lookup_element function in the tst22api.ex module but not when it is typed in iex as an isolated command (after the project load, iex -S mix (minus the tst22api.ex module))? I am relatively new to Elixir and any insights would be greatly appreciated.
This is happening because the httpoison application wasn’t started.
1 Like
It’s likely that something that HTTPoison
depends on is trying to access an ETS table, and it’s not there yet since the call to Tst22api.fetch_user()
happens at compile-time. The stack trace would help readers of your post to see what’s happening.
You get different behavior when making that call in iex -S mix
because that has booted the application’s dependency tree.
2 Likes
Hi Matt
Firstly, thanks for replying so quickly to my post. I am trying to “see” the component load sequence. It sounds like you are telling me that when I exclude the tst22api.ex module from the “iex -S mix” project load and enter the {:ok, response} = HTTPoison.get “https://jsonplaceholder.typicode.com/users/1”
command directly the complete dependency set is effectively loaded (or has been loaded) to effect the access to the json API, but when I include the tst22api.ex module in the iex -S mix project load it is failing to include some dependency at the “compile time”. Is this correct? Is this a timing issue? Here is the complete error stack below to help you help me. Again, thanks so much for your help so quickly!
== Compilation error in file lib/servy/tst22api.ex ==
** (ArgumentError) errors were found at the given arguments:
* 1st argument: the table identifier does not refer to an existing ETS table
(stdlib 4.3.1.3) :ets.lookup_element(:hackney_config, :mod_metrics, 2)
(hackney 1.20.1) c:/Users/Gordon/lessontst/servy/deps/hackney/src/hackney_metrics.erl:27: :hackney_metrics.get_engine/0
(hackney 1.20.1) c:/Users/Gordon/lessontst/servy/deps/hackney/src/hackney_connect.erl:75: :hackney_connect.create_connection/5
(hackney 1.20.1) c:/Users/Gordon/lessontst/servy/deps/hackney/src/hackney_connect.erl:44: :hackney_connect.connect/5
(hackney 1.20.1) c:/Users/Gordon/lessontst/servy/deps/hackney/src/hackney.erl:335: :hackney.request/5
(httpoison 2.2.1) lib/httpoison/base.ex:888: HTTPoison.Base.request/6
lib/servy/tst22api.ex:7: Tst22api.fetch_user/0
lib/servy/tst22api.ex:14: (file)
Hi v0idpwn
Thank you for answering this post so quickly. I am not seeing the load sequence correctly – I think. Since it is the case that when the {:ok, response} = HTTPoison.get(“https://jsonplaceholder.typicode.com/users/1”) is entered directly after the iex -S mix command is invoked (without the tst22api.ex module included in the project load) and it works, does this mean that the httpoison application has enough time to start, but when that same command is encountered during the project load (iex -S mix) when tst22api.ex is included the httpoison application does not does not have enough time to start due to compile time? This seems to me the only variable between the two scenarios. For further insight the “httpoison” application is included in the mix.exs file, both in the deps and application sections. Again, thanks for the quick response!! Just in case it may be Germain I have included the entire error stack below.
== Compilation error in file lib/servy/tst22api.ex ==
** (ArgumentError) errors were found at the given arguments:
- 1st argument: the table identifier does not refer to an existing ETS table
(stdlib 4.3.1.3) :ets.lookup_element(:hackney_config, :mod_metrics, 2)
(hackney 1.20.1) c:/Users/Gordon/lessontst/servy/deps/hackney/src/hackney_metrics.erl:27: :hackney_metrics.get_engine/0
(hackney 1.20.1) c:/Users/Gordon/lessontst/servy/deps/hackney/src/hackney_connect.erl:75: :hackney_connect.create_connection/5
(hackney 1.20.1) c:/Users/Gordon/lessontst/servy/deps/hackney/src/hackney_connect.erl:44: :hackney_connect.connect/5
(hackney 1.20.1) c:/Users/Gordon/lessontst/servy/deps/hackney/src/hackney.erl:335: :hackney.request/5
(httpoison 2.2.1) lib/httpoison/base.ex:888: HTTPoison.Base.request/6
lib/servy/tst22api.ex:7: Tst22api.fetch_user/0
lib/servy/tst22api.ex:14: (file)
(a general note: format code with triple-backticks (```
) before and after to avoid it being processed as Markdown)
The stacktrace shows that Hackney is trying to access an ETS table and failing.
The root cause is the final line of tst22api.ex
that calls fetch_user
, which runs when the file is compiled and thus before Mix has started the application’s dependencies.
You might get farther by adding Application.ensure_started(:hackney)
right before the call to fetch_user
, if calling that function when the module is compiled is required.
1 Like
I was able to resolve the issue by creating a “run()” function inside the Tst22api module that called the fetch_user function. I then used the “mix run -e Tst22api.run()” call to execute the code. This forced the dependency loads that I needed and the code ran without error. Thanks to everyone that reached out to me.
Respectfully,
Ideprize
1 Like