Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error handling in edge promises #661

Merged
merged 1 commit into from Jul 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
@@ -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:
Expand Down
4 changes: 2 additions & 2 deletions lib/concurrent/edge/promises.rb
Expand Up @@ -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
Expand Down
14 changes: 13 additions & 1 deletion spec/concurrent/edge/promises_spec.rb
Expand Up @@ -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

Expand All @@ -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
Expand Down