Skip to content

Instantly share code, notes, and snippets.

@donnoman
Created July 30, 2010 21:23
Show Gist options
  • Save donnoman/501342 to your computer and use it in GitHub Desktop.
Save donnoman/501342 to your computer and use it in GitHub Desktop.
Discovered Issue with Bundler with Logging 1.2.2
boot.rb patches the initialzer to memoize the Bundler.require
the preinitializer runs
The environment.rb is loaded
logging is required before the Rails::Initializer.run
require 'logging'
Rails::Initializer.run do |config|
..some commands that use logging...
end
logging/utils.rb adds require! and require? methods to Kernel
it also inits two global variables:
# Settiing this global variable to +false+ will disable rubygems from
# being loaded at all.
$use_rubygems = true unless defined? $use_rubygems
# Setting this global variable to +true+ will cause an error message to be
# displayed when a library cannot be required.
$whiny_require = false unless defined? $whiny_require
logging.rb does a require? 'fastthread'
require? which is meant to suppress any exceptions when trying to load an OPTIONAL dependency calls require!
require! calls require
# call-seq:
# require!( string )
# require!( string, gem_version )
# require!( string, gem_name, gem_version )
#
# Attempt to the load the library named _string_ using the standard
# Kernel#require method. If the library cannot be loaded then require
# rubygems and retry the original require of the library.
#
# Raises a LoadError if the library cannot be loaded.
#
# If a _gem_version_ is given, then the rubygems +gem+ command is used to
# load the specific version of the gem. The library _string_ is used for
# the _gem_name_ if one is omitted.
#
def require!( string, *args )
return require(string) if args.empty?
name, version = *args
version, name = name, string if name =~ %r/^[0-9<>=~]/
version ||= '> 0'
gem name, version
require(string)
rescue LoadError, NoMethodError
retry if $use_rubygems and require('rubygems')
if $whiny_require
name ||= string
$stderr.puts "Required library #{string.inspect} could not be loaded."
$stderr.puts "Try:\tgem install #{name}"
end
raise
end
require throws an exception of MissingSourceFile and enters the rescue block (Though I'm not sure why)
it hits the retry
$use_rubygems by default is true, and require('rubygems') returns an empty array, which evaluates to true.
And thus enters an infinite loop.
Solutions:
put the following:
$use_rubygems = false
$whiny_require = true
In your environment.rb before requiring logging
need to upgrade to latest version of logging, these methods have been updated on the version in master.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment