Skip to content

Commit

Permalink
Merge pull request #192 from connectedbits/dont-swallow-nested-failures
Browse files Browse the repository at this point in the history
Don't rescue Failures from other contexts
  • Loading branch information
gaffneyc authored Jan 24, 2022
2 parents 952263e + 119ee9c commit 1337985
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
5 changes: 4 additions & 1 deletion lib/interactor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,10 @@ def initialize(context = {})
# Returns nothing.
def run
run!
rescue Failure
rescue Failure => e
if context.object_id != e.context.object_id
raise
end
end

# Internal: Invoke an Interactor instance along with all defined hooks. The
Expand Down
12 changes: 10 additions & 2 deletions spec/support/lint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,22 @@
instance.run
end

it "rescues failure" do
expect(instance).to receive(:run!).and_raise(Interactor::Failure)
it "rescues failure with the same context" do
expect(instance).to receive(:run!).and_raise(Interactor::Failure.new(instance.context))

expect {
instance.run
}.not_to raise_error
end

it "raises other failures" do
expect(instance).to receive(:run!).and_raise(Interactor::Failure.new(Interactor::Context.new))

expect {
instance.run
}.to raise_error(Interactor::Failure)
end

it "raises other errors" do
expect(instance).to receive(:run!).and_raise("foo")

Expand Down

0 comments on commit 1337985

Please sign in to comment.