summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThe Bundler Bot <bot@bundler.io>2018-03-16 12:25:41 +0000
committerThe Bundler Bot <bot@bundler.io>2018-03-16 12:25:41 +0000
commit7f4c1a81b7b92e234fce0e3592d27c396d2451ac (patch)
treed1eb7da5b7a0df2e819ed5557d852325d611926c
parentb7b847fe734dc8d95782d2e6510c8bc9a6631374 (diff)
parente24e8be8c749b16ffe8ac9548651e50024429954 (diff)
downloadbundler-7f4c1a81b7b92e234fce0e3592d27c396d2451ac.tar.gz
Auto merge of #6343 - nesaulov:fix-nil-backtrace, r=colby-swandale
Fix failure when exception backtrace is nil Resolves #6342 ### What was the end-user problem that led to this PR? Instead of throwing a readable error, Bundler failed and generated an issue report template (see details in #6342). ### What was your diagnosis of the problem? My diagnosis was that nil safety is hard in Ruby. ### What is your fix for the problem, implemented in this PR? To check whether backtrace is nil before sending it a `take_while` method. ### Why did you choose this fix out of the possible options? I chose this fix because I see no other solutions.
-rw-r--r--lib/bundler/cli/exec.rb2
-rw-r--r--spec/commands/exec_spec.rb30
2 files changed, 31 insertions, 1 deletions
diff --git a/lib/bundler/cli/exec.rb b/lib/bundler/cli/exec.rb
index d6ac453676..386565c575 100644
--- a/lib/bundler/cli/exec.rb
+++ b/lib/bundler/cli/exec.rb
@@ -77,7 +77,7 @@ module Bundler
rescue Exception => e # rubocop:disable Lint/RescueException
Bundler.ui = ui
Bundler.ui.error "bundler: failed to load command: #{cmd} (#{file})"
- backtrace = e.backtrace.take_while {|bt| !bt.start_with?(__FILE__) }
+ backtrace = e.backtrace ? e.backtrace.take_while {|bt| !bt.start_with?(__FILE__) } : []
abort "#{e.class}: #{e.message}\n #{backtrace.join("\n ")}"
end
diff --git a/spec/commands/exec_spec.rb b/spec/commands/exec_spec.rb
index 5c11129dd8..30972b5e46 100644
--- a/spec/commands/exec_spec.rb
+++ b/spec/commands/exec_spec.rb
@@ -606,6 +606,36 @@ RSpec.describe "bundle exec" do
it_behaves_like "it runs"
end
+ context "the executable raises an error without a backtrace", :bundler => "< 2" do
+ let(:executable) { super() << "\nclass Err < Exception\ndef backtrace; end;\nend\nraise Err" }
+ let(:exit_code) { 1 }
+ let(:expected) { super() << "\nbundler: failed to load command: #{path} (#{path})" }
+ let(:expected_err) do
+ if ENV["BUNDLER_SPEC_SUB_VERSION"] == "1.98"
+ "Err: Err"
+ else
+ "bundler: failed to load command: #{path} (#{path})\nErr: Err"
+ end
+ end
+
+ it_behaves_like "it runs"
+ end
+
+ context "the executable raises an error without a backtrace", :bundler => "2" do
+ let(:executable) { super() << "\nclass Err < Exception\ndef backtrace; end;\nend\nraise Err" }
+ let(:exit_code) { 1 }
+ let(:expected_err) { "bundler: failed to load command: #{path} (#{path})\nErr: Err" }
+ let(:expected) do
+ if ENV["BUNDLER_SPEC_SUB_VERSION"] == "1.98"
+ super() << "\nbundler: failed to load command: #{path} (#{path})"
+ else
+ super()
+ end
+ end
+
+ it_behaves_like "it runs"
+ end
+
context "when the file uses the current ruby shebang" do
let(:shebang) { "#!#{Gem.ruby}" }
it_behaves_like "it runs"