Skip to content

Commit

Permalink
Make method(:throw_failure) the default handler
Browse files Browse the repository at this point in the history
  • Loading branch information
waiting-for-dev committed Oct 27, 2024
1 parent 9919891 commit 2ca6b0b
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions lib/dry/operation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,12 @@ def step(result)
# failure is encountered. It's meant to be used within the {#steps} block
# commonly wrapping a sub-set of {#step} calls.
#
# @param handler [#call] a callable that will be called with the encountered failure
# @param handler [#call] a callable that will be called with the encountered failure.
# By default, it throws `FAILURE_TAG` with the failure.
# @yieldreturn [Object]
# @return [Object] the block's return value when it's not a failure or the handler's
# return value when the block returns a failure
def intercepting_failure(handler, &block)
def intercepting_failure(handler = method(:throw_failure), &block)
output = catching_failure(&block)

case output
Expand Down
2 changes: 1 addition & 1 deletion lib/dry/operation/extensions/active_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def included(klass)
# @see Dry::Operation#steps
# @see https://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/DatabaseStatements.html#method-i-transaction
klass.define_method(:transaction) do |connection = default_connection, **opts, &steps|
intercepting_failure(method(:throw_failure)) do
intercepting_failure do
result = nil
connection.transaction(**options.merge(opts)) do
intercepting_failure(->(failure) {
Expand Down
2 changes: 1 addition & 1 deletion lib/dry/operation/extensions/rom.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def included(klass)
that returns the ROM container
MSG

intercepting_failure(method(:throw_failure)) do
intercepting_failure do
result = nil
rom.gateways[gateway].transaction do |t|
intercepting_failure(->(failure) {
Expand Down

0 comments on commit 2ca6b0b

Please sign in to comment.