ideprize

ideprize

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.

Showing Posts 1 to 6

v0idpwn

v0idpwn

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

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.

ideprize

ideprize OP

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)
ideprize

ideprize OP

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)

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 OP

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

— All posts loaded —

Where Next? Top

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
jonnycharles
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
spammy
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
dli
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app? Looking for hints regarding: Addi...
New
roeland
Kia ora, We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
New
bottlenecked
Hi all, I wanted to ask how the community is dealing with post-release steps. Today we have Ecto migrations, which make sure that the db...
New
rahultumpala
Hello, I have an Elixir backend that implements a custom protocol over TCP. I want to load test the backend and assess the performance o...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews