Skip to content

Conversation

@ixti
Copy link

@ixti ixti commented Dec 17, 2020

Is there an reason to not sue catch(...) { throw ... } instead of { begin; raise ...; rescue ...; end`?

@flash-gordon
Copy link
Member

There is, it's even mentioned in the docs https://dry-rb.org/gems/dry-monads/1.3/do-notation/#transaction-safety Also see #98 (comment)

@ixti
Copy link
Author

ixti commented Dec 18, 2020

Oh, I missed that indeed. But I find rationale to be somewhat questionable - it's somewhat a side-effect that works ATM for some gems (AR and ROM). And IMHO it makes code less obvious.

Without do-notation one would write something like (pseudocode):

repo.transaction do |t|
  foo.bind { |v| bar.bind(v) }.or { t.rollback! }
end

So, I was expecting do-notation to provide me only fail-fast railroad. For transaction handling I would wrap my code separately:

repo.transaction do |t|
  method_with_do_notation.or { t.rollback! }
end

@flash-gordon
Copy link
Member

You can have your own version of do notation in your code, nothing stops you from building one. When it comes to the gem I want safer defaults and, besides, my projects' code relies on the current behavior. I believe the same is true for other people since it's mentioned in the docs.

In summary, it's an intentional design choice, but you're right, using catch/throw would be equivalent to some extent.

@ixti
Copy link
Author

ixti commented Dec 19, 2020

Fair point.

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

Successfully merging this pull request may close these issues.

2 participants