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

handling of exceptions that define a #initialize method inconsistent w.r.t. MRI #168

Closed
doudou opened this Issue Jan 17, 2010 · 5 comments

Comments

Projects
None yet
4 participants
@doudou
Contributor

doudou commented Jan 17, 2010

Given the following script:

class MyException < Exception
  def initialize(arg)
    STDERR.puts "arg: #{arg}"
  end
end

begin
  instance = MyException.new(10)
  STDERR.puts "raise instance: #{instance.object_id}"
  raise instance, "test"
rescue MyException => e
  STDERR.puts "rescued instance: #{e.object_id}"
end

MRI's Kernel#raise will dup the exception instance's and modify its message and backtrace:

[~]% ruby --version
ruby 1.8.7 (2010-01-10 patchlevel 249) [x86_64-linux]
[~]% ruby test.rb
arg: 10
raise instance: 70211455400300
rescued instance: 70211455399240

(Actually, MRI is a bit inconsistent, since it will not explicitely call #dup or #clone but will call #initialize_copy anyway. But that's common with MRI)

On rubinius, "raise" seems to create a new exception of the same class than +instance+ (NOT duping it), and gives the message to the #initialize method of the instance:

[~]% rbx --version
rubinius 1.0.0-rc2 (1.8.7 74d5ea9d 2010-01-04 JI) [x86_64-unknown-linux-gnu]
[~]% rbx test.rb
arg: 10
raise instance: 562
arg: test
rescued instance: 568

This obviously breaks any exception scheme that uses exception instances with additional information embedded in them.

@doudou

This comment has been minimized.

Show comment
Hide comment
@doudou

doudou Jan 17, 2010

Contributor

Tentative fix:

http://github.com/doudou/rubinius/commit/80b5fe30187eccf58eb40626300c1972d6285433

Forget this commit .. I thought I was passing the mspec, but the RBC file was not updated even though I ran "rake kernel".

Should not rbx detect if the rbc file is up-to-date ????

Contributor

doudou commented Jan 17, 2010

Tentative fix:

http://github.com/doudou/rubinius/commit/80b5fe30187eccf58eb40626300c1972d6285433

Forget this commit .. I thought I was passing the mspec, but the RBC file was not updated even though I ran "rake kernel".

Should not rbx detect if the rbc file is up-to-date ????

@doudou

This comment has been minimized.

Show comment
Hide comment
Contributor

doudou commented Jan 17, 2010

@dbussink

This comment has been minimized.

Show comment
Hide comment
@dbussink

dbussink Feb 5, 2010

Member

Could you please also provide additional rubyspecs for this case? Each bugfix should also have a rubyspec so this behavior can also be validated for other implementations and it is included into continuous integration.

Member

dbussink commented Feb 5, 2010

Could you please also provide additional rubyspecs for this case? Each bugfix should also have a rubyspec so this behavior can also be validated for other implementations and it is included into continuous integration.

@stormbrew

This comment has been minimized.

Show comment
Hide comment
@stormbrew

stormbrew Feb 5, 2010

Member

Posted an updated patch (with requested changes) of my spec change from duplicate issue #175 that should work with the above patch as well as my own original patch.

http://gist.github.com/296153

Member

stormbrew commented Feb 5, 2010

Posted an updated patch (with requested changes) of my spec change from duplicate issue #175 that should work with the above patch as well as my own original patch.

http://gist.github.com/296153

@evanphx

This comment has been minimized.

Show comment
Hide comment
@evanphx

evanphx Feb 8, 2010

Member

Exception#exception is crazy. Closed by c40a935.

Implementation by github:stormbrew

Member

evanphx commented Feb 8, 2010

Exception#exception is crazy. Closed by c40a935.

Implementation by github:stormbrew

This issue was closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment