diff options
author | The Bundler Bot <bot@bundler.io> | 2017-10-18 20:06:22 +0000 |
---|---|---|
committer | Samuel Giddins <segiddins@segiddins.me> | 2017-10-30 13:54:28 -0500 |
commit | c4b77b0b7d3c47f5c334d3fb6e701a81a77d496d (patch) | |
tree | 5db7df5877f9a0ddeaebbd18c58124cdb6d2a0a0 | |
parent | 6b5ac1869efe3e93695096d4ff767b79764c073f (diff) | |
download | bundler-c4b77b0b7d3c47f5c334d3fb6e701a81a77d496d.tar.gz |
Auto merge of #6092 - dekellum:do-not-rescue-signal-exception, r=segiddins
Avoid bundle exec rescue of SignalException
Avoid rescue of SignalException in kernel_load and with_friendly_errors This allows SignalException to be handled gracefully by the ruby interpreter.
This supersedes #6091.
### What was the end-user problem that led to this PR?
Fixes #6090
### What was your diagnosis of the problem?
CLI::Exec#kernel_load should not rescue the SignalException. Neither should with_friendly_errors, so it unwinds all the way to the ruby interpreter.
### What is your fix for the problem, implemented in this PR?
Two rescue and re-raises specific to SignalException.
### Why did you choose this fix out of the possible options?
My first naive attempt was #6091, where I had missed the outer rescue in with_friendly_errors, all of the other special friendly error behavior, and the spec dependencies. While I still suspect that kernel_load and friendly_errors might be rescuing/handling more than they should (for comparison: binstub doesn't do this) this is a much more minimal, safer, and easier fix to #6090.
(cherry picked from commit 6d0b74cde28ea0c1724f37ff799cd7524ff0d9b4)
-rw-r--r-- | lib/bundler/cli/exec.rb | 2 | ||||
-rw-r--r-- | lib/bundler/friendly_errors.rb | 2 | ||||
-rw-r--r-- | spec/commands/exec_spec.rb | 20 |
3 files changed, 23 insertions, 1 deletions
diff --git a/lib/bundler/cli/exec.rb b/lib/bundler/cli/exec.rb index 4b4a621879..2fdc614fbb 100644 --- a/lib/bundler/cli/exec.rb +++ b/lib/bundler/cli/exec.rb @@ -73,7 +73,7 @@ module Bundler signals = Signal.list.keys - RESERVED_SIGNALS signals.each {|s| trap(s, "DEFAULT") } Kernel.load(file) - rescue SystemExit + rescue SystemExit, SignalException raise rescue Exception => e # rubocop:disable Lint/RescueException Bundler.ui = ui diff --git a/lib/bundler/friendly_errors.rb b/lib/bundler/friendly_errors.rb index 51dd60c931..f624185773 100644 --- a/lib/bundler/friendly_errors.rb +++ b/lib/bundler/friendly_errors.rb @@ -120,6 +120,8 @@ module Bundler def self.with_friendly_errors yield + rescue SignalException + raise rescue Exception => e FriendlyErrors.log_error(e) exit FriendlyErrors.exit_status(e) diff --git a/spec/commands/exec_spec.rb b/spec/commands/exec_spec.rb index add997f049..c32b760a1e 100644 --- a/spec/commands/exec_spec.rb +++ b/spec/commands/exec_spec.rb @@ -540,6 +540,26 @@ RSpec.describe "bundle exec" do end end + context "the executable exits by SignalException" do + let(:executable) do + ex = super() + ex << "\n" + if LessThanProc.with(RUBY_VERSION).call("1.9") + # Ruby < 1.9 needs a flush for a exit by signal, later + # rubies do not + ex << "STDOUT.flush\n" + end + ex << "raise SignalException, 'SIGTERM'\n" + ex + end + let(:exit_code) do + # signal mask 128 + plus signal 15 -> TERM + # this is specified by C99 + 128 + 15 + end + it_behaves_like "it runs" + end + context "the executable is empty", :bundler => "< 2" do let(:executable) { "" } |