henriquesati

henriquesati

I’m using Mnesia with Memento. The compiler it’s warning that the return type {:error, _} | {:ok, _} will never match my with clause (I will append the code), but when I test the function, it only returns the :ok atom

  def swap_pk(payload, public, new_contract) do
    Logger.debug("contract: #{inspect(new_contract)}")
    Logger.debug("old pk: #{payload}")
    Logger.debug("new pk: #{public}")

    try do
      with :ok <- delete_record_by_pk(payload),
           {:ok, record} <- insert_record(public, @awaiting_payment, new_contract) do
        {:ok, record}
      else
        _ ->
          Logger.error("Erro durante swap_pk")
          error = FormatError.initerror("erro", "swap_pk")
          {:error, error }
      end
    rescue
      exception ->
        Logger.error("swap_pk failed: #{inspect(exception)}")
        {:error, exception}
    end
  end

    @spec delete_record_by_pk(any()) :: {:error, any()} | {:ok, any()}
  @doc "Deleta um registro pelo primary key."
  def delete_record_by_pk(pk) do
    Logger.debug("ab")
    req = Memento.transaction(fn ->
      Query.delete(MnesiaContract, pk)
    end)
    Logger.debug("delete_record_by_pk response: #{req}")
    req
  end

as you can see, the spec is typed as a tuple

14:38:53.970 [debug] contract: %{name: "Test Contract", value: 100}
14:38:53.978 [debug] old pk: test_pk_123
14:38:53.978 [debug] new pk: new_pk_456
14:38:53.978 [debug] ab
14:38:53.978 [debug] delete_record_by_pk response: ok

as you can see, the response is purely the :ok, but the compiler keeps typing it as a tuple

Showing Posts 1 to 3

al2o3cr

al2o3cr

If you tell Dialyzer things that aren’t true, it will believe you :stuck_out_tongue:

I suspect fixing the return value to be {:error, any()} | :ok will fix things.

Edit: it also appears that the spec for Memento.Transaction.execute is wrong; it’s listed as {:error, any()} | {:ok, any()} but actually comes from Memento.Mnesia.handle_result, which can only return {:error, any()} | :ok:

https://github.com/sheharyarn/memento/blob/b27a1ad654bdc9200c82d5e74e86624a03edc1d7/lib/memento/mnesia.ex#L62-L84

henriquesati

henriquesati OP

I dont know how are the type system currently working, but I do not have to type anything, it automatically types everytime I run my code. I tried to erase the incorrect typing, but it keeps generating this one

henriquesati

henriquesati OP

btw ill take a look on this answer to where i’m doing the wrong thing, thanks!

— 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
leoschweizer
Hi, we run different LLM models across a cluster, with each node loading a configurable subset. Model-specific queues let nodes consume ...
New
Stef-Verniers
Hello I’ve been coding in Elixir for almost two years now because of my current job where we implemented Elixir in our application. But ...
New
csmr
Hi all, I’m new here and would like to hear peoples views on my Elixir/Phoenix based game-engine! :smiley: Mutonex gamedesign was finish...
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
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
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

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews