[ruby/timeout] Make Timeout::Error#exception with multiple arguments not ignore arguments
This makes: raise(Timeout::Error.new("hello"), "world") raise a TimeoutError instance with "world" as the message instead of "hello", for consistency with other Ruby exception classes. This required some internal changes to keep the tests passing. Fixes [Bug #17812] https://github.com/ruby/timeout/commit/952154dbf9
This commit is contained in:
parent
a42b7de436
commit
33b5e179a8
@ -32,7 +32,9 @@ module Timeout
|
|||||||
def self.catch(*args)
|
def self.catch(*args)
|
||||||
exc = new(*args)
|
exc = new(*args)
|
||||||
exc.instance_variable_set(:@thread, Thread.current)
|
exc.instance_variable_set(:@thread, Thread.current)
|
||||||
::Kernel.catch(exc) {yield exc}
|
catch_value = Object.new
|
||||||
|
exc.instance_variable_set(:@catch_value, catch_value)
|
||||||
|
::Kernel.catch(catch_value) {yield exc}
|
||||||
end
|
end
|
||||||
|
|
||||||
def exception(*)
|
def exception(*)
|
||||||
@ -40,11 +42,11 @@ module Timeout
|
|||||||
if self.thread == Thread.current
|
if self.thread == Thread.current
|
||||||
bt = caller
|
bt = caller
|
||||||
begin
|
begin
|
||||||
throw(self, bt)
|
throw(@catch_value, bt)
|
||||||
rescue UncaughtThrowError
|
rescue UncaughtThrowError
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
self
|
super
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -115,6 +117,7 @@ module Timeout
|
|||||||
begin
|
begin
|
||||||
bl.call(klass)
|
bl.call(klass)
|
||||||
rescue klass => e
|
rescue klass => e
|
||||||
|
message = e.message
|
||||||
bt = e.backtrace
|
bt = e.backtrace
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
@ -80,6 +80,14 @@ class TestTimeout < Test::Unit::TestCase
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_raise_with_message
|
||||||
|
bug17812 = '[ruby-core:103502] [Bug #17812]: Timeout::Error doesn\'t let two-argument raise() set a new message'
|
||||||
|
exc = Timeout::Error.new('foo')
|
||||||
|
assert_raise_with_message(Timeout::Error, 'bar', bug17812) do
|
||||||
|
raise exc, 'bar'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_enumerator_next
|
def test_enumerator_next
|
||||||
bug9380 = '[ruby-dev:47872] [Bug #9380]: timeout in Enumerator#next'
|
bug9380 = '[ruby-dev:47872] [Bug #9380]: timeout in Enumerator#next'
|
||||||
e = (o=Object.new).to_enum
|
e = (o=Object.new).to_enum
|
||||||
|
Loading…
x
Reference in New Issue
Block a user