diff options
author | Jeremy Evans <[email protected]> | 2021-04-20 10:34:11 -0700 |
---|---|---|
committer | Hiroshi SHIBATA <[email protected]> | 2021-05-06 16:49:26 +0900 |
commit | 33b5e179a88e67f1ee12e2e8993121b2f445b54f (patch) | |
tree | 1fb74a99fbe9c9b57280ac224dcef17e34346738 /lib/timeout.rb | |
parent | a42b7de436cfceb0d6607651a3a7bf4fbd887416 (diff) |
[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
Diffstat (limited to 'lib/timeout.rb')
-rw-r--r-- | lib/timeout.rb | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/lib/timeout.rb b/lib/timeout.rb index 11db4be973..572e90cafb 100644 --- a/lib/timeout.rb +++ b/lib/timeout.rb @@ -32,7 +32,9 @@ module Timeout def self.catch(*args) exc = new(*args) 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 def exception(*) @@ -40,11 +42,11 @@ module Timeout if self.thread == Thread.current bt = caller begin - throw(self, bt) + throw(@catch_value, bt) rescue UncaughtThrowError end end - self + super end end @@ -115,6 +117,7 @@ module Timeout begin bl.call(klass) rescue klass => e + message = e.message bt = e.backtrace end else |