diff --git a/lib/dry/monads/do.rb b/lib/dry/monads/do.rb index e2a59a6c..f1f5183d 100644 --- a/lib/dry/monads/do.rb +++ b/lib/dry/monads/do.rb @@ -10,7 +10,7 @@ module Do extend Mixin # @api private - class Halt < StandardError + class Halt < Exception # @api private attr_reader :result diff --git a/spec/integration/do_spec.rb b/spec/integration/do_spec.rb index 19685d11..25f63c74 100644 --- a/spec/integration/do_spec.rb +++ b/spec/integration/do_spec.rb @@ -106,7 +106,7 @@ def call def transaction yield - rescue => e + rescue Exception => e @rolled_back = true raise e end @@ -118,6 +118,27 @@ def transaction expect(instance.rolled_back).to be(true) end end + + context 'with rescue block in method' do + before do + klass.class_eval do + def call(m1) + yield m1 + raise "oops" + rescue => e + Failure("handled exception: #{e}") + end + end + end + + it 'catches standard exception' do + expect(instance.call(Success(1))).to eql(Failure("handled exception: oops")) + end + + it 'does not catch Halt exception' do + expect(instance.call(Failure(5))).to eql(Failure(5)) + end + end end context 'with Maybe' do