[Rubygems-developers] LoadError in nested require causes silent failure

Peter Marklund peter_marklund at fastmail.fm
Mon Jan 29 15:13:51 EST 2007

I've thought a bit more about how RubyGems overrides the Ruby require  
method and how it deals with LoadErrors and it seems to me that there  
is general issue with the contract of the Ruby require method being  
changed, and also, and more seriously, of silent failures. Consider  
the following example. We have a system with the Rails gem installed  
and the file test_helper.rb can be found in that gem. Suppose we have  
a file in the current directory called test_helper.rb that only  

require 'b'

where the file b doesn't exist. Then, with RubyGems no exception is  
thrown when requiring the test_help.rb file:

irb(main):001:0> require 'rubygems'
=> true
irb(main):002:0> require 'test_help'
=> false

According to the contract of require this would indicate that  
"test_help" has already been loaded, which is true in a sense, but  
the load failure is never exposed.

Without RubyGems an exception is thrown on the first invocation of  
require, but not the second:

require File.join(File.dirname(__FILE__), "test_help")
LoadError: no such file to load -- b
	from ./test_help.rb:1:in `require'
	from ./test_help.rb:1
	from (irb):1
irb(main):002:0> require File.join(File.dirname(__FILE__), "test_help")
=> false

I hope this illustrates the issue that I am getting at. RubyGems  
cannot know that the LoadError exception refers to the path of the  
require, it can refer to a nested require. When the second invocation  
of __require in RubyGems require method returns false, should  
RubyGems maybe issue a warning?



Peter Marklund
Garvar Lundins Gränd 7
11220 Stockholm

Mobile Phone: +46-(0)70-4164857
Home Phone: +46-(0)8-50091315
Skype: peter_marklund

IM: AIM - petermarklund, MSN - peter_marklund at hotmail.com, Yahoo -  


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/rubygems-developers/attachments/20070129/c5127f24/attachment.html 

More information about the Rubygems-developers mailing list