henriquesati

henriquesati

I’m doing a POST request using Req but i’m getting the error ** (ArgumentError) unknown registry: Req.Finch. I found the same problem on elixir reddit but I couldnt manage to understand and apply the possible solution
My code:

defmodule GetPayloadInfo do

  def doReq do
    token = "XXX"
    req = Req.Request.new(method: :post, url: "https://sandbox.asaas.com/api/v3/pix/qrCodes/decode")
    req = Req.Request.put_headers(req, [{"accept", "application/json"}, {"acess_token", token}, {"content-type", "application/json"} ])

    {req, resp} = Req.Request.run_request(req)
  end

end

Then I simply call the function on my main file with a simple hello world output so make sure its all fine before this

Hello.say_hi()
GetPayloadInfo.doReq()

and this is my mix.exs file

defmodule TestesPay.MixProject do
  use Mix.Project

  def project do
    [
      app: :testes_pay,
      version: "0.1.0",
      elixir: "~> 1.16",
      start_permanent: Mix.env() == :prod,
      deps: deps()
    ]
  end

  # Run "mix help compile.app" to learn about applications.
  def application do
    [
      extra_applications: [:logger],
      telemetry: [enabled: false],
    ]
  end

  # Run "mix help deps" to learn about dependencies.
  defp deps do
    [
      {:req, "~> 0.5.0"}
      # {:dep_from_hexpm, "~> 0.3.0"},
      # {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"}
    ]
  end
end
the code contains no scripts, only .ex files, located at lib

Showing Posts 1 to 10

henriquesati

henriquesati OP

== Compilation error in file lib/cry.ex ==
** (ArgumentError) unknown registry: Req.Finch
    (elixir 1.16.3) lib/registry.ex:1400: Registry.key_info!/1
    (elixir 1.16.3) lib/registry.ex:590: Registry.lookup/2
    (finch 0.18.0) lib/finch/pool_manager.ex:46: Finch.PoolManager.lookup_pool/2
    (finch 0.18.0) lib/finch/pool_manager.ex:34: Finch.PoolManager.get_pool/3
    (finch 0.18.0) lib/finch.ex:428: Finch.__stream__/5
    (finch 0.18.0) lib/finch.ex:472: anonymous fn/4 in Finch.request/3
    (telemetry 1.2.1) c:/Users/pedro/OneDrive/Área de Trabalho/testes_pay/deps/telemetry/src/telemetry.erl:321: :telemetry.span/3
    (req 0.5.1) lib/req/steps.ex:977: Req.Steps.run_finch_request/3

the full compilation error in case it helps

wojtekmach

wojtekmach

Hex Core Team
== Compilation error in file lib/cry.ex ==

Oh, you’re using Req at compile-time, i.e. in module body and similar. In that case it seems you need to explicitly start dependencies:

defmodule Foo do
  {:ok, _} = Application.ensure_all_started(:req)
  Req.get(...)
end
henriquesati

henriquesati OP

Thanks for you help, it worked. Application its a built in module in elixir/mix and ensure_all_started all is another module (or method, I don’t know how things are exactly referenced in lixir) that ensures all dependencies a module uses are loaded before the module itself?
I dont quite get the ''using req at compile-time", there is another way os using it?

wojtekmach

wojtekmach

Hex Core Team

compile-time vs runtime is a pretty broad topic so to just scratch the surface when you have a module:

def Foo do
  IO.puts :at_compile_time

  def foo do
    IO.puts :at_runtime
  end
end

the first IO.puts is executed while the module is being compiled. When it is being used at runtime, that IO.puts will not be executed. On the other hand, the second IO.puts is NOT executed when the module is being compiled. It is only executed when you call Foo.foo(). Doing things at compile-time is definitely an Elixir super power and for this particular use case you need that Application.ensure_all_started. (The reason is Req library starts a supervision tree in its application callback module. If it didn’t, ensure_all_started would not be necessary.) In vast majority of day to day Elixir programming, you don’t need ensure_all_started, it is done for you.

dimitarvp

dimitarvp

No, not at all. Modules are loaded just fine but there is the concept of applications that start various OTP processes which is achieved by the applications themselves being “started” (“application” being a useful abstraction here).

jswanner

jswanner

Are you sure you want to be using Req at compile time? I suspect you want to move your use of Req into a function so that you can use it while your application is running

henriquesati

henriquesati OP

what do you mean by that? I have no idea what i’m doing to be real, i’m learning elixir and the lib now, the docs aren’t helping much, i’m stuck in pretty basic things

BrightEyesDavid

BrightEyesDavid

What does your “main file” look like?

Others will correct me if I’m wrong, but I think, based on @wojtekmach’s answer, it’s because your function calls are not themselves in a function, so they call functions at compile time instead of run time:

Try putting those function calls in a function:

defmodule Main do
  def go do
    Hello.say_hi()
    GetPayloadInfo.doReq()
  end
end

Then (without the Application.ensure_all_started), run the Main.go function in iex (in the directory containing your Mix project):

$ iex -S mix
iex> Main.go
LorenzoD

LorenzoD

For those finding this thread after running into this error when using Req in a function within a Mix.Task module: This problem is resolved by adding @requirements ["app.start"] at the module level. This ensures that Req and its dependencies are available for use when you execute the Mix task.

More information can be found in the documentation here.

— 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
water
I’m aware of 2 such projects, are there others? git: GitHub - team-alembic/realworld: A fullstack Phoenix LiveView application with back...
New
itzmidinesh
Hi all, I’m working on a Phoenix project where I need to make external HTTP requests and I’m trying to choose between Req and HTTPoison....
New
pragdave
How do I tell Hologram not to escape HTML when substituting into templates? {Textile.render(@product.long_description)} escapes the HTM...
New
rlipscombe
I’d like to create a file with 600 permissions (rw-------), but there’s a race condition if I create it and then change the permissions. ...
New
leoschweizer
Hi, we run different LLM models across a cluster, with each node loading a configurable subset. Model-specific queues let nodes consume ...
New
rlipscombe
When I use Mix.install with a git dependency, using git@github.com:... how do I change the SSH identity used? I’ve got two Github accoun...
New

Other Trending Topics Top

dominicletz
Hey there, I haven’t seen a list of useful Elixir specific skills for the popular AI tools yet so I’m starting one here with my first. ...
New
raa-ziq
Hi everyone :waving_hand: I wanted to share something I’ve been building — NowBlind, a random chat app designed to help people discover ...
New
mudasobwa
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
OndrejValenta
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly) AI dream has many faces, but general...
New
kip
Localize is the next generation localisation library for Elixir. Think of it as ex_cldr version 3.0. The first version will be released ...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews