summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Rodríguez <[email protected]>2025-01-24 17:46:47 +0100
committerHiroshi SHIBATA <[email protected]>2025-01-28 15:31:57 +0900
commit9b2ebfc7294a61eec32962be0547dec8321b8330 (patch)
tree951d8d2dc137df0506a57297f9d000c6705d17a4
parent83b4de8520e6ef10dfb0207c923f8ad343282d6d (diff)
[rubygems/rubygems] Fix bug report template incorrectly showing up
If a gem has an internal error, that should not make `bundle console` print the bug report template. https://github.com/rubygems/rubygems/commit/7432a9a084
-rw-r--r--lib/bundler/runtime.rb13
-rw-r--r--spec/bundler/commands/console_spec.rb174
-rw-r--r--spec/bundler/runtime/require_spec.rb53
3 files changed, 123 insertions, 117 deletions
diff --git a/lib/bundler/runtime.rb b/lib/bundler/runtime.rb
index dc25b116df..1225eb9f50 100644
--- a/lib/bundler/runtime.rb
+++ b/lib/bundler/runtime.rb
@@ -62,11 +62,14 @@ module Bundler
begin
Kernel.require required_file
rescue LoadError => e
- raise if dep.autorequire || e.path != required_file
-
- if required_file.include?("-")
- required_file = required_file.tr("-", "/")
- retry
+ if dep.autorequire.nil? && e.path == required_file
+ if required_file.include?("-")
+ required_file = required_file.tr("-", "/")
+ retry
+ end
+ else
+ raise Bundler::GemRequireError.new e,
+ "There was an error while trying to load the gem '#{file}'."
end
rescue RuntimeError => e
raise Bundler::GemRequireError.new e,
diff --git a/spec/bundler/commands/console_spec.rb b/spec/bundler/commands/console_spec.rb
index c0770a4322..ecb4877b3a 100644
--- a/spec/bundler/commands/console_spec.rb
+++ b/spec/bundler/commands/console_spec.rb
@@ -42,106 +42,134 @@ RSpec.describe "bundle console", readline: true do
RUBY
end
end
-
- install_gemfile <<-G
- source "https://gem.repo2"
- gem "myrack"
- gem "activesupport", :group => :test
- gem "myrack_middleware", :group => :development
- G
end
- it "starts IRB with the default group loaded" do
- bundle "console" do |input, _, _|
- input.puts("puts MYRACK")
- input.puts("exit")
- end
- expect(out).to include("0.9.1")
- end
+ context "when the library has an unrelated error" do
+ before do
+ build_lib "loadfuuu", "1.0.0" do |s|
+ s.write "lib/loadfuuu.rb", "require_relative 'loadfuuu/bar'"
+ s.write "lib/loadfuuu/bar.rb", "require 'not-in-bundle'"
+ end
- it "uses IRB as default console" do
- bundle "console" do |input, _, _|
- input.puts("__FILE__")
- input.puts("exit")
+ install_gemfile <<-G
+ source "https://gem.repo1"
+ path "#{lib_path}" do
+ gem "loadfuuu", require: true
+ end
+ G
end
- expect(out).to include("(irb)")
- end
- it "starts another REPL if configured as such" do
- install_gemfile <<-G
- source "https://gem.repo2"
- gem "pry"
- G
- bundle "config set console pry"
+ it "does not show the bug report template" do
+ bundle("console", raise_on_error: false) do |input, _, _|
+ input.puts("exit")
+ end
- bundle "console" do |input, _, _|
- input.puts("__method__")
- input.puts("exit")
+ expect(err).not_to include("ERROR REPORT TEMPLATE")
end
- expect(out).to include(":__pry__")
end
- it "falls back to IRB if the other REPL isn't available" do
- bundle "config set console pry"
- # make sure pry isn't there
+ context "when the library does not have any errors" do
+ before do
+ install_gemfile <<-G
+ source "https://gem.repo2"
+ gem "myrack"
+ gem "activesupport", :group => :test
+ gem "myrack_middleware", :group => :development
+ G
+ end
- bundle "console" do |input, _, _|
- input.puts("__FILE__")
- input.puts("exit")
+ it "starts IRB with the default group loaded" do
+ bundle "console" do |input, _, _|
+ input.puts("puts MYRACK")
+ input.puts("exit")
+ end
+ expect(out).to include("0.9.1")
end
- expect(out).to include("(irb)")
- end
- it "doesn't load any other groups" do
- bundle "console" do |input, _, _|
- input.puts("puts ACTIVESUPPORT")
- input.puts("exit")
+ it "uses IRB as default console" do
+ bundle "console" do |input, _, _|
+ input.puts("__FILE__")
+ input.puts("exit")
+ end
+ expect(out).to include("(irb)")
end
- expect(out).to include("NameError")
- end
- describe "when given a group" do
- it "loads the given group" do
- bundle "console test" do |input, _, _|
- input.puts("puts ACTIVESUPPORT")
+ it "starts another REPL if configured as such" do
+ install_gemfile <<-G
+ source "https://gem.repo2"
+ gem "pry"
+ G
+ bundle "config set console pry"
+
+ bundle "console" do |input, _, _|
+ input.puts("__method__")
input.puts("exit")
end
- expect(out).to include("2.3.5")
+ expect(out).to include(":__pry__")
end
- it "loads the default group" do
- bundle "console test" do |input, _, _|
- input.puts("puts MYRACK")
+ it "falls back to IRB if the other REPL isn't available" do
+ bundle "config set console pry"
+ # make sure pry isn't there
+
+ bundle "console" do |input, _, _|
+ input.puts("__FILE__")
input.puts("exit")
end
- expect(out).to include("0.9.1")
+ expect(out).to include("(irb)")
end
- it "doesn't load other groups" do
- bundle "console test" do |input, _, _|
- input.puts("puts MYRACK_MIDDLEWARE")
+ it "doesn't load any other groups" do
+ bundle "console" do |input, _, _|
+ input.puts("puts ACTIVESUPPORT")
input.puts("exit")
end
expect(out).to include("NameError")
end
- end
- it "performs an automatic bundle install" do
- gemfile <<-G
- source "https://gem.repo2"
- gem "myrack"
- gem "activesupport", :group => :test
- gem "myrack_middleware", :group => :development
- gem "foo"
- G
-
- bundle "config set auto_install 1"
- bundle :console do |input, _, _|
- input.puts("puts 'hello'")
- input.puts("exit")
+ describe "when given a group" do
+ it "loads the given group" do
+ bundle "console test" do |input, _, _|
+ input.puts("puts ACTIVESUPPORT")
+ input.puts("exit")
+ end
+ expect(out).to include("2.3.5")
+ end
+
+ it "loads the default group" do
+ bundle "console test" do |input, _, _|
+ input.puts("puts MYRACK")
+ input.puts("exit")
+ end
+ expect(out).to include("0.9.1")
+ end
+
+ it "doesn't load other groups" do
+ bundle "console test" do |input, _, _|
+ input.puts("puts MYRACK_MIDDLEWARE")
+ input.puts("exit")
+ end
+ expect(out).to include("NameError")
+ end
+ end
+
+ it "performs an automatic bundle install" do
+ gemfile <<-G
+ source "https://gem.repo2"
+ gem "myrack"
+ gem "activesupport", :group => :test
+ gem "myrack_middleware", :group => :development
+ gem "foo"
+ G
+
+ bundle "config set auto_install 1"
+ bundle :console do |input, _, _|
+ input.puts("puts 'hello'")
+ input.puts("exit")
+ end
+ expect(out).to include("Installing foo 1.0")
+ expect(out).to include("hello")
+ expect(the_bundle).to include_gems "foo 1.0"
end
- expect(out).to include("Installing foo 1.0")
- expect(out).to include("hello")
- expect(the_bundle).to include_gems "foo 1.0"
end
end
diff --git a/spec/bundler/runtime/require_spec.rb b/spec/bundler/runtime/require_spec.rb
index ece6679eb2..46613286d2 100644
--- a/spec/bundler/runtime/require_spec.rb
+++ b/spec/bundler/runtime/require_spec.rb
@@ -119,11 +119,9 @@ RSpec.describe "Bundler.require" do
end
G
- load_error_run <<-R, "fail"
- Bundler.require
- R
+ run "Bundler.require", raise_on_error: false
- expect(err_without_deprecations).to eq("ZOMG LOAD ERROR")
+ expect(err_without_deprecations).to include("cannot load such file -- fail")
end
it "displays a helpful message if the required gem throws an error" do
@@ -155,16 +153,9 @@ RSpec.describe "Bundler.require" do
end
G
- cmd = <<-RUBY
- begin
- Bundler.require
- rescue LoadError => e
- warn "ZOMG LOAD ERROR: \#{e.message}"
- end
- RUBY
- run(cmd)
+ run "Bundler.require", raise_on_error: false
- expect(err_without_deprecations).to eq("ZOMG LOAD ERROR: cannot load such file -- load-bar")
+ expect(err_without_deprecations).to include("cannot load such file -- load-bar")
end
describe "with namespaced gems" do
@@ -215,10 +206,9 @@ RSpec.describe "Bundler.require" do
end
G
- load_error_run <<-R, "jquery-rails"
- Bundler.require
- R
- expect(err_without_deprecations).to eq("ZOMG LOAD ERROR")
+ run "Bundler.require", raise_on_error: false
+
+ expect(err_without_deprecations).to include("cannot load such file -- jquery-rails")
end
it "handles the case where regex fails" do
@@ -233,16 +223,9 @@ RSpec.describe "Bundler.require" do
end
G
- cmd = <<-RUBY
- begin
- Bundler.require
- rescue LoadError => e
- warn "ZOMG LOAD ERROR" if e.message.include?("Could not open library 'libfuuu-1.0'")
- end
- RUBY
- run(cmd)
+ run "Bundler.require", raise_on_error: false
- expect(err_without_deprecations).to eq("ZOMG LOAD ERROR")
+ expect(err_without_deprecations).to include("libfuuu-1.0").and include("cannot open shared object file")
end
it "doesn't swallow the error when the library has an unrelated error" do
@@ -257,16 +240,9 @@ RSpec.describe "Bundler.require" do
end
G
- cmd = <<-RUBY
- begin
- Bundler.require
- rescue LoadError => e
- warn "ZOMG LOAD ERROR: \#{e.message}"
- end
- RUBY
- run(cmd)
+ run "Bundler.require", raise_on_error: false
- expect(err_without_deprecations).to eq("ZOMG LOAD ERROR: cannot load such file -- load-bar")
+ expect(err_without_deprecations).to include("cannot load such file -- load-bar")
end
end
@@ -375,10 +351,9 @@ RSpec.describe "Bundler.require" do
gem "busted_require"
G
- load_error_run <<-R, "no_such_file_omg"
- Bundler.require
- R
- expect(err_without_deprecations).to eq("ZOMG LOAD ERROR")
+ run "Bundler.require", raise_on_error: false
+
+ expect(err_without_deprecations).to include("cannot load such file -- no_such_file_omg")
end
end
end