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

Don't swallow LoadErrors when requiring a dashed gem #3195

Merged
merged 1 commit into from
Oct 3, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Don't swallow LoadErrors when requiring a dashed gem
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 2, 2014
commit 7abc2846fed546d190ec0504d780cc75d52bcc66
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