Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Commit

Permalink
Don't swallow LoadErrors when requiring a dashed gem
Browse files Browse the repository at this point in the history
This looks like #1807

when raising a LoadError in a required gem, bundler will rescue it to try and see if it came from his own namespaced require or from the required file.

If it comes from the dashed require it will re-raise the original exception in case the gem was dashed but the first require was ok but raised a LoadError after.

However, the exception is swallowed if we require a dashed gem without the proper file name, for example gem name : 'foo-bar' and file architecture : 'foo/bar.rb'

This PR raise the exception back in case it really comes from inside the namespaced file.
  • Loading branch information
Intrepidd authored and Adrien Siami committed Oct 1, 2014
1 parent 9772abe commit a53c9b7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
5 changes: 2 additions & 3 deletions lib/bundler/runtime.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,10 @@ def require(*groups)
begin
namespaced_file = dep.name.gsub('-', '/')
Kernel.require namespaced_file
rescue LoadError
rescue LoadError => e
REGEXPS.find { |r| r =~ e.message }
regex_name = $1
raise e if dep.autorequire || (regex_name && regex_name.gsub('-', '/') != namespaced_file)
raise e if regex_name.nil?
raise if regex_name != namespaced_file
end
end
end
Expand Down
25 changes: 24 additions & 1 deletion spec/runtime/require_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,28 @@
expect(err).to eq("ZOMG LOAD ERROR")
end

it "doesn't swallow the error when the library has an unrelated error" do
build_lib "loadfuuu", "1.0.0" do |s|
s.write "lib/loadfuuu.rb", "raise LoadError.new(\"cannot load such file -- load-bar\")"
end

gemfile <<-G
path "#{lib_path}"
gem "loadfuuu"
G

cmd = <<-RUBY
begin
Bundler.require
rescue LoadError => e
$stderr.puts "ZOMG LOAD ERROR: \#{e.message}"
end
RUBY
run(cmd, :expect_err => true)

expect(err).to eq("ZOMG LOAD ERROR: cannot load such file -- load-bar")
end

describe "with namespaced gems" do
before :each do
build_lib "jquery-rails", "1.0.0" do |s|
Expand Down Expand Up @@ -170,8 +192,9 @@

it "doesn't swallow the error when the library has an unrelated error" do
build_lib "load-fuuu", "1.0.0" do |s|
s.write "lib/load-fuuu.rb", "raise LoadError.new(\"cannot load such file -- load-bar\")"
s.write "lib/load/fuuu.rb", "raise LoadError.new(\"cannot load such file -- load-bar\")"
end
lib_path('load-fuuu-1.0.0/lib/load-fuuu.rb').rmtree

gemfile <<-G
path "#{lib_path}"
Expand Down

0 comments on commit a53c9b7

Please sign in to comment.