Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If some of the interactors of the organizer fail error message is not persisted. #169

Closed
majksner opened this issue Feb 8, 2020 · 3 comments · Fixed by #174
Closed

If some of the interactors of the organizer fail error message is not persisted. #169

majksner opened this issue Feb 8, 2020 · 3 comments · Fixed by #174
Labels
bug Something isn't working verified This issue has been verified.
Milestone

Comments

@majksner
Copy link

majksner commented Feb 8, 2020

If some of the interactors of the organizer fail context.fail!('Error Message') error message is not persisted.

[10] pry(main)> stripe = StripeCustomer::UpdateCustomer.perform(user: user, params: params)
stripe.success?
=> false

[10] pry(main)> stripe.errors
=> #<ActiveModel::Errors:0x00007fa730422528
 @base=
  #<StripeCustomer::UpdateCustomer::Context user=#<User id: 104..>, params={...}>,
 @details={},
 @messages={}>

Initially reported in #167

@majksner majksner added bug Something isn't working unverified This issue has not been verified labels Feb 8, 2020
@aaronmallen aaronmallen added organizer verified This issue has been verified. and removed unverified This issue has not been verified labels Feb 10, 2020
@aaronmallen aaronmallen added this to the v1.0.3 milestone Feb 10, 2020
@aaronmallen
Copy link
Owner

@majksner can you provide a minimal reproduction case with the interactors and organizers included?

@majksner
Copy link
Author

Create directory app/interactors/test_interactor then put test.rb and prepare.rb in it.

test.rb

module TestInteractor
  class Test < ApplicationOrganizer
    organize do
      add TestInteractor::Prepare
    end
  end
end

prepare.rb

module TestInteractor
  class Prepare < ApplicationInteractor
    def perform
      context.fail!('Something Went Wrong')
    end
  end
end

then open Rails console

[6] pry(main)> result = TestInteractor::Test.perform()
[8] pry(main)> result.success?
=> false
[9] pry(main)> result.errors
=> #<ActiveModel::Errors:0x00007ffa88328180 @base=#<TestInteractor::Test::Context>, @details={}, @messages={}>

messages are empty here, I expect to see an error message from the interactor Something Went Wrong

Then running Interactor directly without involving an organizer provides an error message.

[10] pry(main)> result = TestInteractor::Prepare.perform()
ActiveInteractor: TestInteractor::Prepare::Context failed!
=> #<TestInteractor::Prepare::Context>

[11] pry(main)> result.errors
=> #<ActiveModel::Errors:0x00007ffa88389138 @base=#<TestInteractor::Prepare::Context>, @details={:context=>[{:error=>"Something Went Wrong"}]}, @messages={:context=>["Something Went Wrong"]}>

@aaronmallen
Copy link
Owner

Research notes: This is happening because we run a validation check after perform is invoked for the :called validation context which is clearing errors previously established in the original invocation of the interactor's perform method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working verified This issue has been verified.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants