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

Peter Marklund peter_marklund at fastmail.fm
Mon Jan 29 14:35:41 EST 2007


Hi!
I have been bitten by a silent failure stemming from, I think, a  
miscommunication between Rails and RubyGems with regards to the  
LoadError exception. In the Rails test_helper.rb file we have a  
require 'test_help' which in turn requires other files, for example  
the application.rb file. In my application.rb file I was trying to  
access a helper file that didn't exist. From within helper.rb Rails  
would then throw a LoadError. RubyGems would catch this LoadError and  
apparently interpret it as "test_help" could not be loaded (which is  
not what Rails was trying to say at all). RubyGems would find  
"test_help" in the Rails gem and try to do a __require "test_help".  
Ruby would then return false and not load the file since it had  
already been loaded and thus the silent failure was a reality. A  
simple way to solve the issue would be to log an error message to the  
Rails log when the helper file is not found.

The reason I am sending this email is that I wonder under which  
circumstances "__require path" inside the require method in RubyGems  
would/should return false? I mean if the file first could not be  
found by Ruby, and RubyGems finds the file and tells Ruby about it  
(by adding it to the load path), and Ruby then won't load the file,  
isn't there a logical inconsistency? Or is the thinking that some  
other thread could have loaded the file in the meantime? My second  
question is if you think Rails is misusing the LoadError class here?

Thanks in advance!

Cheers

Peter


----------------------------
Peter Marklund
Garvar Lundins Gränd 7
11220 Stockholm
Sweden

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 -  
peter_marklund2002

http://marklunds.com
----------------------------



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


More information about the Rubygems-developers mailing list