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.

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

srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call th...
New
dotdotdotPaul
Okay, I'm having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I'm sure I'...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
sacepums
Hey guys. I'm new to elixir and im really stocked about it. But I ran into a bit of problem - I need to convert a date sting, for examp...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lis...
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
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
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

Other popular topics Top

JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
dotdotdotPaul
Okay, I'm having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I'm sure I'...
New
yawaramin
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
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
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
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
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
AstonJ
by Lance Halvorsen Elixir and Phoenix are generating tremendous excitement as an unbeatable platform for building modern web application...
460 27162 124
New

We're in Beta

About us Mission Statement