collectiveidea / interactor

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

context.fail! is confusing, behaviour has changed, docs haven't #90

Closed matthucke closed 7 years ago

matthucke commented 9 years ago

In Version 3, context.fail! always throws an exception:

    # Raises Interactor::Failure initialized with the Interactor::Context.
    def fail!(context = {})
      modifiable.update(context)
      @failure = true
      raise Failure, self
    end

In version 2, it did not. The README is still showing the version 2 behaviour, where the caller queries success? after.

What is the current best practice to indicate and respond to failure? I liked the old idiom of checking context.success? from the controller, after the interactor has returned. Yet now it seems we must rescue instead - a change that disrupts the structure of the controller methods.

Could we provide a non-throwing 'fail' method in addition to the throwing version? (I'm currently using a Rails initializer to monkey-patch one in).

laserlemon commented 9 years ago

Are you using the class method call or the instance method?

matthucke commented 9 years ago

Neither. I was testing internal business-logic methods of my interactor directly - before writing a call that would combine them in sequence.

Reading the source, I discover that call swallows exceptions from fail!, while call! does not.

I'll submit a modification to the README that clarifies this.

[edit] Pull request #91 submitted.

laserlemon commented 7 years ago

Merged #91.