Skip to content

Commit cb9e31f

Browse files
Merge pull request #8443 from rubygems/deivid-rodriguez/remove-unnecessary-console-fallback
Fix `bundle console` unnecessarily trying to load IRB twice (cherry picked from commit 790a202)
1 parent dff8ab7 commit cb9e31f

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

bundler/lib/bundler/cli/console.rb

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,14 @@ def get_console(name)
2020
require name
2121
get_constant(name)
2222
rescue LoadError
23-
Bundler.ui.error "Couldn't load console #{name}, falling back to irb"
24-
require "irb"
25-
get_constant("irb")
23+
if name == "irb"
24+
Bundler.ui.error "#{name} is not available"
25+
exit 1
26+
else
27+
Bundler.ui.error "Couldn't load console #{name}, falling back to irb"
28+
name = "irb"
29+
retry
30+
end
2631
end
2732

2833
def get_constant(name)
@@ -32,9 +37,6 @@ def get_constant(name)
3237
"irb" => :IRB,
3338
}[name]
3439
Object.const_get(const_name)
35-
rescue NameError
36-
Bundler.ui.error "Could not find constant #{const_name}"
37-
exit 1
3840
end
3941
end
4042
end

bundler/spec/commands/console_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,17 @@ def __pry__
113113
expect(out).to include("(irb)")
114114
end
115115

116+
it "does not try IRB twice if no console is configured and IRB is not available" do
117+
create_file("irb.rb", "raise LoadError, 'irb is not available'")
118+
119+
bundle("console", env: { "RUBYOPT" => "-I#{bundled_app} #{ENV["RUBYOPT"]}" }, raise_on_error: false) do |input, _, _|
120+
input.puts("puts ACTIVESUPPORT")
121+
input.puts("exit")
122+
end
123+
expect(err).not_to include("falling back to irb")
124+
expect(err).to include("irb is not available")
125+
end
126+
116127
it "doesn't load any other groups" do
117128
bundle "console" do |input, _, _|
118129
input.puts("puts ACTIVESUPPORT")

0 commit comments

Comments
 (0)