Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions eval.c
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,12 @@ rb_exception_setup(int argc, VALUE *argv)
if (resolved_cause == exception) {
resolved_cause = Qnil;
}

// A non-local exit in flight keeps its throw data in errinfo, and
// throw data is not an exception:
if (THROW_DATA_P(resolved_cause)) {
resolved_cause = Qnil;
}
}
else if (NIL_P(cause)) {
// Explicit nil cause - prevent chaining:
Expand Down
31 changes: 31 additions & 0 deletions test/ruby/test_exception.rb
Original file line number Diff line number Diff line change
Expand Up @@ -949,6 +949,37 @@ def test_cause_thread_with_cause
assert_equal("caller's cause", e.cause.message)
end

# Thread#raise and Fiber#raise take their implicit cause from errinfo, which
# holds throw data while a non-local exit is in flight. The exception queued
# here is delivered when Thread.handle_interrupt returns, and leaving the
# block with `break` makes that happen while the break is still unwinding.
# The VM calls #exception on the queued object at that point.
def assert_cause_not_throw_data(raiser)
assert_separately([], "#{<<~"begin;"}\n#{<<~"end;"}")
begin;
e = nil
begin
Thread.handle_interrupt(Object => :never) do
queued = StandardError.new("queued")
Thread.current.raise(queued)
queued.define_singleton_method(:exception) {|*| #{raiser}.raise("in flight")}
break
end
rescue => e
end
assert_equal("in flight", e.message)
assert_nil(e.cause)
end;
end

def test_cause_thread_raise_not_throw_data
assert_cause_not_throw_data("Thread.current")
end

def test_cause_fiber_raise_not_throw_data
assert_cause_not_throw_data("Fiber.current")
end

def test_unknown_option
bug = '[ruby-core:63203] [Feature #8257] should pass unknown options'

Expand Down
Loading