Question about error in Ecto Transaction with Multi

In the run docs it is written that I need return {:error, value} to rollback, if I a return exit/1 or a exception, also rollback in the same way or I need use try/catch and return {:error, value}?

2 Likes

https://hexdocs.pm/ecto/Ecto.Repo.html#c:transaction/2 is where it is actually run from, and as you can see there it states that:

In case of any errors the transaction will be rolled back and {:error, failed_operation, failed_value, changes_so_far} will be returned.

Specifically only in the case of success will it be committed, if it returns an error, errors, fails in any other way, system dies, whatever, then it will rollback.

3 Likes