If some of the interactors of the organizer fail error message is not persisted.
majksner opened this issue · 3 comments
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 can you provide a minimal reproduction case with the interactors and organizers included?
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"]}>
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.