ideprize

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

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

v0idpwn

This is happening because the httpoison application wasn’t started.

al2o3cr

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.

Last Post!

ideprize

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

Where Next?

Popular in Questions Top

hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a > b) do {:ok, "a"} end if (a < b) do {:ok, b} end if (a == b) do {:ok, "equa...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New

Other popular topics Top

openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 44139 214
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New

We're in Beta

About us Mission Statement