#Calling Tesla module in a mix task

1 messages · Page 1 of 1 (latest)

rancid roost
#

Ive create a module with a tesla get request inside of it, and when trying to call a mix task that calls that module i get this error

jacob@DESKTOP-DJ5HGIC:~/aoc$ mix one
** (ArgumentError) errors were found at the given arguments:

  * 1st argument: the table identifier does not refer to an existing ETS table

    (stdlib 4.1.1) :ets.lookup_element(:hackney_config, :mod_metrics, 2)
    (hackney 1.18.1) /home/jacob/aoc/deps/hackney/src/hackney_metrics.erl:27: :hackney_metrics.get_engine/0
    (hackney 1.18.1) /home/jacob/aoc/deps/hackney/src/hackney_connect.erl:75: :hackney_connect.create_connection/5
    (hackney 1.18.1) /home/jacob/aoc/deps/hackney/src/hackney_connect.erl:44: :hackney_connect.connect/5
    (hackney 1.18.1) /home/jacob/aoc/deps/hackney/src/hackney.erl:335: :hackney.request/5
    (tesla 1.4.4) lib/tesla/adapter/hackney.ex:71: Tesla.Adapter.Hackney.request/5
    (tesla 1.4.4) lib/tesla/adapter/hackney.ex:33: Tesla.Adapter.Hackney.call/2
    (aoc 0.1.0) lib/aoc.ex:10: Aoc.get_input/1
#

The mix task is simply this

defmodule Mix.Tasks.One do
  use Mix.Task

  def run(_) do
    Aoc.One.run
  end
end

Which calls get_input in this module

defmodule Aoc do
  use Tesla

  @session_token Application.compile_env(:aoc, :session_token)

  plug Tesla.Middleware.BaseUrl, "https://adventofcode.com/2022/day/"
  plug Tesla.Middleware.Headers, [{"Cookie", "session=#{@session_token}"}]

  def get_input(day) do
    case get(to_string(day) <> "/input") do
      {:ok, resp} -> check_status resp
      {:error, reason} -> IO.puts("Error: #{reason.body}")
    end
  end

  def check_status(resp) do
    case resp.status do
      200 -> parse_input(resp.body)
      _ -> IO.puts("Error: #{resp.body}")
    end
  end

  def parse_input(body) do
    body
  end
end
#

but if i go into iex and call the method it works fine