Skip to content
This repository has been archived by the owner on Jul 1, 2021. It is now read-only.

Ruby 1.9.3p392 (and probably any 1.9 Ruby) incorrectly stringify RbVmomi::Fault in raise #17

Open
slippycheeze opened this issue Apr 25, 2013 · 0 comments

Comments

@slippycheeze
Copy link

One of the semantic changes in Ruby 1.9 was to start using methods like String#to_str blindly, and relying on the MethodMissing exception to determine that the facility isn't supported.

This, in turn, leads to calling raise on an explicitly created instance of RbVmomi::Fault (from 1.6.0) raising a RuntimeError instance - because RbVmomi::Fault delegates to_str to the @fault member, and that responds with a string, so Kernel#raise treats it as if you called raise RbVmomi::Fault.new(...).to_s instead.

1.9.3p392 :002 > begin
1.9.3p392 :003 >     raise RbVmomi::Fault.new('foo', 'bar')
1.9.3p392 :004?>   rescue Exception => e
1.9.3p392 :005?>     e.class
1.9.3p392 :006?>   end
 => RuntimeError

I discovered this in a test where we stubbed out raising the exception class, but it would also apply to all the instances in the gem that raise on a manually created RbVmomi::Fault class - they will throw RuntimeError, and bypass explicit catching in at least some versions of Ruby 1.9.3.

The easiest resolution to this is to exclude to_str from the method_missing implementation, allowing it to raise the traditional NoMethodError exception, and through that cause the Ruby runtime to behave as expected.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant