[Rubygems-developers] Load errors squashed

Nicholas Seckar nseckar at gmail.com
Wed Jul 20 16:18:27 EDT 2005

Hello guys,

I've run into an issue in RubyGems where load errors are swallowed by 

Allow me to describe the situation as I have come to understand it:

Assume RubyGems is loaded. Say that we perform require 'fcgi_handler'.

Rubygems' implementation of require sets up an exception handler for 
LoadError and calls require__ (the built-in require).

Assuming fcgi_handler.rb is present, it is read and evaluated.

Suppose that fcgi_handler.rb calls require 'fcgi'

Rubygems' again wraps require__. Suppose fcgi isn't present? require 
catches' require__'s exception and looks for a gem containing fcgi.rb. 
Suppose the fcgi gem isn't installed? RubyGems' require re-raises the 

The exception is raised past require__('fcgi_handler') and into 
require('fcgi_handler'), where it is caught. RubyGems *wrongfully* 
assumes that the load error is related to missing fcgi_handler.rb, and 
looks for a gem with fcgi_handler.rb. It finds rails, and require's it, 
and continues on merrily.


The above URL leads to a patch which corrects this behavior. It inspects 
the call stack and re-raises the exception if the load error did not 
occur while loading the current file.

It does so by checking the exceptions's stack trace and ensuring that 
all the methods contain the word require. This is done to play fair with 
other require hooks, but you may choose to simplify this.

If you prefer,
   raise if load_error.backtrace.length > caller.length + 2
will raise the error unless the require__ method was the source of the 

You will also notice the lact of unit-tests. I'm quite unfamiliar with 
RubyGems' test setup, and I don't have the time to absorb it. Hopefully 
another soul can provide this...

Nicholas Seckar

-------------- next part --------------
Index: actionpack/lib/action_controller/request.rb
--- actionpack/lib/action_controller/request.rb	(revision 1854)
+++ actionpack/lib/action_controller/request.rb	(working copy)
@@ -153,12 +153,9 @@
       path = (uri = request_uri) ? uri.split('?').first : ''
       # Cut off the path to the installation directory if given
-      if root = relative_url_root
-        path[root.length..-1]
-      else
-        path
-      end
-    end    
+      path[0, root.length] = '' if root = relative_url_root
+      path || ''
+    end
     # Returns the path minus the web server relative installation directory.
     # This method returns nil unless the web server is apache.

More information about the Rubygems-developers mailing list