You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jul 1, 2021. It is now read-only.
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.
The text was updated successfully, but these errors were encountered:
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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 ofRbVmomi::Fault
(from 1.6.0) raising aRuntimeError
instance - becauseRbVmomi::Fault
delegatesto_str
to the@fault
member, and that responds with a string, soKernel#raise
treats it as if you calledraise RbVmomi::Fault.new(...).to_s
instead.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 throwRuntimeError
, 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 themethod_missing
implementation, allowing it to raise the traditionalNoMethodError
exception, and through that cause the Ruby runtime to behave as expected.The text was updated successfully, but these errors were encountered: