Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Commit

Permalink
Auto merge of #6092 - dekellum:do-not-rescue-signal-exception, r=segi…
Browse files Browse the repository at this point in the history
…ddins

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.
  • Loading branch information
bundlerbot committed Oct 18, 2017
2 parents 0132573 + b10910a commit 6d0b74c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/bundler/cli/exec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def kernel_load(file, *args)
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
Expand Down
2 changes: 2 additions & 0 deletions lib/bundler/friendly_errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ def issues_url(exception)

def self.with_friendly_errors
yield
rescue SignalException
raise
rescue Exception => e
FriendlyErrors.log_error(e)
exit FriendlyErrors.exit_status(e)
Expand Down
20 changes: 20 additions & 0 deletions spec/commands/exec_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,26 @@ def bin_path(a,b,c)
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) { "" }

Expand Down

0 comments on commit 6d0b74c

Please sign in to comment.