interactor icon indicating copy to clipboard operation
interactor copied to clipboard

`fail!` raises self, which is an OpenStruct and `to_s` on the exception loads ActiveRecord Relations

Open thekendalmiller opened this issue 6 years ago • 0 comments

We recently updated the interactor gem and ran into an interesting issue where fail! would trigger any ActiveRecord relations passed in the context to be evaluated.

The issue ended up being because of a rescue in one of our interactors doing exception.to_s'. And because the context is an OpenStruct, to_s would print out the results of the ActiveRecord relations because for each key, it does value.inspect

Here is a very simple reproduction that works in console.

class SimpleTest
  include Interactor

  def call
    begin
      context.fail!
    rescue => e
      puts e.to_s
    end
  end
end

SimpleTest.call(offices: Somemodel.all, users: AnotherModel.all);

The fix we are using is adding a to_s in Interactor::Failure. If someone wants to access the context, it's already on Failure here: https://github.com/collectiveidea/interactor/blob/master/lib/interactor/error.rb#L27

Would this fix be something you are interested in having a Pull Request for? If so I can submit one.

Thanks

thekendalmiller avatar May 22 '20 19:05 thekendalmiller