Bug #9354

timeout() custom exception class cannot require argument

Added by Aman Gupta 3 months ago. Updated about 1 month ago.

[ruby-core:59511]
Status:Closed
Priority:Normal
Assignee:Yui NARUSE
Category:lib
Target version:next minor
ruby -v:trunk Backport:1.9.3: DONTNEED, 2.0.0: DONTNEED, 2.1: DONE

Description

The following code works on 2.0.0, but raises on 2.1.0:

require 'timeout'
class MyError < StandardError
def initialize(msg)
super
end
end
timeout(1, MyError){}

$ ruby -v
ruby 2.1.0p0-github (2013-12-31 revision 44488) [x86_64-darwin13.0]
$ ruby /tmp/test.rb
/tmp/test.rb:4:in `initialize': wrong number of arguments (0 for 1) (ArgumentError)

The patch attached resolves this issue.

timeout_klass_arg.patch Magnifier (795 Bytes) Aman Gupta, 01/03/2014 07:09 PM

Associated revisions

Revision 44517
Added by Nobuyoshi Nakada 3 months ago

timeout.rb: defer creating custom exception

  • lib/timeout.rb (Timeout#timeout): when a custom exception is given, no instance is needed to be caught, so defer creating new instance until it is raised. [Bug #9354]

History

#1 Updated by Aman Gupta 3 months ago

#2 Updated by Nobuyoshi Nakada 3 months ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r44517.
Aman, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


timeout.rb: defer creating custom exception

  • lib/timeout.rb (Timeout#timeout): when a custom exception is given, no instance is needed to be caught, so defer creating new instance until it is raised. [Bug #9354]

#3 Updated by Aman Gupta 3 months ago

  • Assignee set to Yui NARUSE
  • Target version set to next minor
  • % Done changed from 100 to 0
  • Backport changed from 1.9.3: UNKNOWN, 2.0.0: UNKNOWN, 2.1: UNKNOWN to 1.9.3: UNKNOWN, 2.0.0: UNKNOWN, 2.1: REQUIRED

Thanks @nobu. This is causing some failures in the faraday gem, so I think we should backport it to 2.1

#4 Updated by Nobuyoshi Nakada 3 months ago

  • Status changed from Closed to Open
  • Assignee deleted (Yui NARUSE)
  • Target version deleted (next minor)
  • Backport changed from 1.9.3: UNKNOWN, 2.0.0: UNKNOWN, 2.1: REQUIRED to 1.9.3: DONTNEED, 2.0.0: DONTNEED, 2.1: REQUIRED

Timeout in 2.0 doesn't use catch/throw, so it doesn't need to backport.

#5 Updated by Nobuyoshi Nakada 3 months ago

  • Category set to lib
  • Assignee set to Yui NARUSE
  • Target version set to next minor

#6 Updated by Yui NARUSE about 1 month ago

  • Status changed from Open to Closed

#7 Updated by Yui NARUSE about 1 month ago

  • Backport changed from 1.9.3: DONTNEED, 2.0.0: DONTNEED, 2.1: REQUIRED to 1.9.3: DONTNEED, 2.0.0: DONTNEED, 2.1: DONE

ruby21 r44841 merged revision(s) 44517,44518,44519,44523.

Also available in: Atom PDF