Skip to content

Commit 264e2c1

Browse files
authored
Merge pull request #661 from hobodave/fix-edge-error-handling
Fix error handling in edge promises
2 parents 7048038 + cced0a7 commit 264e2c1

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## Current
2+
3+
concurrent-ruby-edge:
4+
5+
* (#659) Edge promises fail during error handling
6+
17
## Release v1.0.5, edge v0.3.1 (26 Feb 2017)
28

39
concurrent-ruby:

lib/concurrent/edge/promises.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -982,12 +982,12 @@ def value!(timeout = nil)
982982
# @return [Exception]
983983
def exception(*args)
984984
raise Concurrent::Error, 'it is not rejected' unless rejected?
985-
reason = Array(internal_state.reason).compact
985+
reason = Array(internal_state.reason).flatten.compact
986986
if reason.size > 1
987987
Concurrent::MultipleErrors.new reason
988988
else
989989
ex = reason[0].exception(*args)
990-
ex.set_backtrace ex.backtrace + caller
990+
ex.set_backtrace Array(ex.backtrace) + caller
991991
ex
992992
end
993993
end

spec/concurrent/edge/promises_spec.rb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,14 @@ def behaves_as_delay(delay, value)
220220
let(:a_future) { future { raise 'error' } }
221221

222222
it 'raises a concurrent error' do
223-
expect { zip(a_future).value! }.to raise_error(StandardError)
223+
expect { zip(a_future).value! }.to raise_error(StandardError, 'error')
224224
end
225225

226+
context 'when deeply nested' do
227+
it 'raises the original error' do
228+
expect { zip(zip(a_future)).value! }.to raise_error(StandardError, 'error')
229+
end
230+
end
226231
end
227232
end
228233

@@ -242,6 +247,13 @@ def behaves_as_delay(delay, value)
242247
end
243248
end
244249

250+
describe '.rejected_future' do
251+
it 'raises the correct error when passed an unraised error' do
252+
f = rejected_future(StandardError.new('boom'))
253+
expect { f.value! }.to raise_error(StandardError, 'boom')
254+
end
255+
end
256+
245257
describe 'Future' do
246258
it 'has sync and async callbacks' do
247259
callbacks_tester = ->(event_or_future) do

0 commit comments

Comments
 (0)