henriquesati
Maybe wrong compiling type warning using memento/mnesia
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
First Post!
al2o3cr
If you tell Dialyzer things that aren’t true, it will believe you ![]()
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:
Popular in Questions
What is the idiomatic way of matching for not nil in Elixir?
E.g.,
First way:
defp halt_if_not_signed_in(conn, signed_in_account) when...
New
Hi all,
Trying to get some more clarity over utc_datetime and naive_datetime for Ecto:
https://hexdocs.pm/ecto/Ecto.Schema.html#module-...
New
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this:
...
New
I have followed this StackOverflow post to install the specific version of Erlang.
And When I am running mix ecto.setup then getting fol...
New
Hello,
I am trying to convert my lists to string without losing brackets.For start i have 3 map. They look like these
buyer = %{
id: ...
New
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
New
I’m currently trying to understand how to join three tables using Ecto. All the examples I’ve seen use 2, so maybe I’m just missing somet...
New
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
Given a string, how can I get access to its character by index? Enum.at("my_string", 2) doesn't work.
Or rather, not char, but a substr...
New
I am trying to run a deploy with docker and I successfully runned with this command:
docker build -t romenigld/blog-prod .
but when I t...
New
Other popular topics
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
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
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
Hi,
I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
Hello, I have map which I want to convert it to string like this:
the map:
%{last_name: "tavakkoli", name: "shahryar"}
the string I ne...
New
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
Hi everyone!
I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
Hey :wave:t3: Elixir community,
I’ve been learning Elixir, and working on some side projects. My editor of choice is VSCode, and althoug...
New







