[Rubygems-developers] LoadError in nested require causes silent failure
peter_marklund at fastmail.fm
Tue Mar 20 17:11:09 EDT 2007
I tried reproducing this problem without Rails as Eric Hodel
suggested and it turned out that the problem has gone away with Ruby
1.8.5. Suppose you have a file test.rb with only one line:
Then in Ruby 1.8.4 you would get:
irb(main):001:0> require 'test'
LoadError: no such file to load -- this_file_does_not_exist
from ./test.rb:1:in `require'
irb(main):002:0> require 'test'
Which means that the second time you require a file that had had a
require statement in it that throws a LoadError Ruby would return
false indicating that the file had already been loaded. If the test
file had been in a Ruby gem then since the RubyGems require method
catches the first LoadError no LoadError would have been thrown for
the first invocation, thus the silent failure.
With Ruby 1.8.5 on the other hand the LoadError will be thrown on the
second require as well and so the silent failure goes away since now
the second time the RubyGems require method invokes the Ruby require
method the LoadError is thrown and propagated.
So to sum up then, the problem has gone away, and all is good and well.
On Jan 29, 2007, at 9:13 PM, Peter Marklund wrote:
> 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 contains:
> 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__),
> => 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 -
Garvar Lundins Gränd 7
Mobile Phone: +46-(0)70-4164857
Home Phone: +46-(0)8-50091315
IM: AIM - petermarklund, MSN - peter_marklund at hotmail.com, Yahoo -
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Rubygems-developers