Permalink
Browse files

Fix error handling in edge promises

* Now properly handles errors raised within deeply nested futures.
* `value!` now properly works with `rejected_future`

Fixes #659
  • Loading branch information...
hobodave committed Jun 6, 2017
1 parent 041c1d1 commit cced0a7eb936f9bf9c688db2c0f2496bfc9833e8
Showing with 21 additions and 3 deletions.
  1. +6 −0 CHANGELOG.md
  2. +2 −2 lib/concurrent/edge/promises.rb
  3. +13 −1 spec/concurrent/edge/promises_spec.rb
View
@@ -1,3 +1,9 @@
## Current
concurrent-ruby-edge:
* (#659) Edge promises fail during error handling
## Release v1.0.5, edge v0.3.1 (26 Feb 2017)
concurrent-ruby:
@@ -982,12 +982,12 @@ def value!(timeout = nil)
# @return [Exception]
def exception(*args)
raise Concurrent::Error, 'it is not rejected' unless rejected?
reason = Array(internal_state.reason).compact
reason = Array(internal_state.reason).flatten.compact
if reason.size > 1
Concurrent::MultipleErrors.new reason
else
ex = reason[0].exception(*args)
ex.set_backtrace ex.backtrace + caller
ex.set_backtrace Array(ex.backtrace) + caller
ex
end
end
@@ -220,9 +220,14 @@ def behaves_as_delay(delay, value)
let(:a_future) { future { raise 'error' } }
it 'raises a concurrent error' do
expect { zip(a_future).value! }.to raise_error(StandardError)
expect { zip(a_future).value! }.to raise_error(StandardError, 'error')
end
context 'when deeply nested' do
it 'raises the original error' do
expect { zip(zip(a_future)).value! }.to raise_error(StandardError, 'error')
end
end
end
end
@@ -242,6 +247,13 @@ def behaves_as_delay(delay, value)
end
end
describe '.rejected_future' do
it 'raises the correct error when passed an unraised error' do
f = rejected_future(StandardError.new('boom'))
expect { f.value! }.to raise_error(StandardError, 'boom')
end
end
describe 'Future' do
it 'has sync and async callbacks' do
callbacks_tester = ->(event_or_future) do

0 comments on commit cced0a7

Please sign in to comment.