diff options
author | The Bundler Bot <bot@bundler.io> | 2018-03-16 12:25:41 +0000 |
---|---|---|
committer | Colby Swandale <me@colby.fyi> | 2018-04-20 10:27:32 +1000 |
commit | 295f928098303d71c0314176f32a7d995b67e3c3 (patch) | |
tree | ac57b85960d7d9a6811cb3ef3bf10a89d0db9e4a | |
parent | e43d3deac9a2e0d620be7d56bc00d403b2601aa8 (diff) | |
download | bundler-295f928098303d71c0314176f32a7d995b67e3c3.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.
(cherry picked from commit 7f4c1a81b7b92e234fce0e3592d27c396d2451ac)
-rw-r--r-- | lib/bundler/cli/exec.rb | 2 | ||||
-rw-r--r-- | spec/commands/exec_spec.rb | 30 |
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 d094c1d578..4a2702fe83 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" |