ideprize
Receiving an error message regarding the access of an ets table
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.
Most Liked
al2o3cr
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.
v0idpwn
This is happening because the httpoison application wasn’t started.
al2o3cr
(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.
ideprize
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







