collectiveidea / interactor

Interactor provides a common interface for performing complex user interactions.
MIT License
3.36k stars 212 forks source link

RFC: Nested failures fail, not raise #211

Open exterm opened 1 year ago

exterm commented 1 year ago

We've been using this library for years, but only recently started adopting call! for fast failures.

We found that the behavior of a nested call! vs a fail! was surprising.

E.g.

class SomeInteractor
  include Interactor

  def call
    context.fail!
  end
end

SomeInteractor.tap(&:call).failure?

# => true

But,

class NestedInteractor
  include Interactor

  def call
    context.fail!
  end
end

class SomeInteractor
  include Interactor

  def call
    NestedInteractor.call!
  end
end

SomeInteractor.tap(&call).failure?
# raises Interactor::Failure exception

We would have expected that SomeInteractor.call shows the same behavior in both cases, catching Failure and returning a context with failure status.

I've attached a (very rough) example implementation in this PR.