Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ecto.Multi errors result in CaseClauseError {:error, :rollback} rather than the error that was raised in the Ecto.Multi function. #73

Open
Qqwy opened this issue Jan 14, 2019 · 2 comments

Comments

@Qqwy
Copy link
Contributor

Qqwy commented Jan 14, 2019

Whenever creating an Ecto.Multi that returns an error.
(Such as by using Ecto.Multi.error or by returning {:error, val} rather than {:ok, val} from an Ecto.Multi.run), this is not properly passed up through the Repo.transaction call.

Furthermore, rather than passing a value up, a CaseClauseError is raised.

Example:

iex> Ecto.Multi.new() |> Ecto.Multi.error(:example, "Foo") |> YourApp.Repo.transaction

Expected result:

{:error, {:example, "Foo", %Ecto.Multi{}}}

Actual result:

** (CaseClauseError) no case clause matching: {:error, :rollback}
    (ecto) lib/ecto/repo/queryable.ex:21: Ecto.Repo.Queryable.transaction/4
@Qqwy Qqwy changed the title Ecto.Multi errors result in {:error, :rollback} rather than the error that was raised in the Ecto.Multi function. Ecto.Multi errors result in CaseClauseError {:error, :rollback} rather than the error that was raised in the Ecto.Multi function. Jan 14, 2019
@AndrewDryga
Copy link
Member

Can you please add Ecto version that you are using?

@Qqwy
Copy link
Contributor Author

Qqwy commented Jan 14, 2019

This is on the newest Ecto that EctoMnesia supports, which is 2.1 IIRC.

I was able to find the cause of this problem, btw. It's here. The rollback function is expected to take the reason as second argument, but EctoMnesia uses an unused _tid argument and hard-codes Mnesia.abort with the reason :rollback.

This causes Ecto.Multi's transaction handling logic (see here to crash because it expects the error result contain a four-element tuple rather than :rollback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants