diff options
author | Nikita Esaulov <billikota@gmail.com> | 2018-03-15 00:34:12 +0300 |
---|---|---|
committer | Nikita Esaulov <billikota@gmail.com> | 2018-03-15 00:34:12 +0300 |
commit | cb41bc398a0d7e1c0e7d3eaa3611475d2f6f6bcd (patch) | |
tree | c1ca767799d544991fb54be6444eb2f4584bd285 | |
parent | 331ade5e654b4cb5cfcafff159593d2bb63d5b1b (diff) | |
download | bundler-cb41bc398a0d7e1c0e7d3eaa3611475d2f6f6bcd.tar.gz |
Fix failure when exception backtrace is nil
-rw-r--r-- | lib/bundler/cli/exec.rb | 2 | ||||
-rw-r--r-- | spec/commands/exec_spec.rb | 20 |
2 files changed, 21 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..05d01ff01d 100644 --- a/spec/commands/exec_spec.rb +++ b/spec/commands/exec_spec.rb @@ -606,6 +606,26 @@ 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_err) do + "bundler: failed to load command: #{path} (#{path})\nErr: Err" + 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) do + "bundler: failed to load command: #{path} (#{path})\nErr: Err" + 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" |