Skip to content

Commit

Permalink
Merge pull request #3450 from rubygems/simplify_nested_exceptions
Browse files Browse the repository at this point in the history
Simplify nested gem activation exceptions
  • Loading branch information
deivid-rodriguez authored and hsbt committed Jan 25, 2021
1 parent 0ae37ee commit e066d19
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
3 changes: 1 addition & 2 deletions lib/rubygems/core_ext/kernel_require.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,7 @@ def require(path)
RUBYGEMS_ACTIVATION_MONITOR.enter

begin
if load_error.message.start_with?("Could not find") or
(load_error.message.end_with?(path) and Gem.try_activate(path))
if load_error.message.end_with?(path) and Gem.try_activate(path)
require_again = true
end
ensure
Expand Down
19 changes: 19 additions & 0 deletions test/rubygems/test_kernel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,25 @@ def test_gem_not_adding_bin
refute $:.any? { |p| %r{a-1/bin} =~ p }
end

def test_gem_failing_inside_require_doesnt_cause_double_exceptions
File.write("activate.rb", "gem('a', '= 999')\n")

require "open3"

output, _ = Open3.capture2e(
{ "GEM_HOME" => Gem.paths.home },
Gem.ruby,
"-I",
File.expand_path("../../lib", __dir__),
"-r",
"./activate.rb"
)

load_errors = output.split("\n").select { |line| line.include?("Could not find")}

assert_equal 1, load_errors.size
end

def test_gem_bundler
quick_gem 'bundler', '1'
quick_gem 'bundler', '2.a'
Expand Down

0 comments on commit e066d19

Please sign in to comment.