Skip to content

Commit

Permalink
Merge pull request #1874 from JuanitoFatas/update-terminology
Browse files Browse the repository at this point in the history
Use clearer terminologies
  • Loading branch information
kyrylo committed Nov 16, 2018
2 parents e87e295 + d12ce06 commit 4fd7307
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 32 deletions.
2 changes: 1 addition & 1 deletion .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ Layout/SpaceInsideStringInterpolation:
# SupportedStyles: final_newline, final_blank_line
Layout/TrailingBlankLines:
Exclude:
- 'spec/exception_whitelist_spec.rb'
- 'spec/unrescued_exceptions_spec.rb'

# Offense count: 13
# Cop supports --auto-correct.
Expand Down
6 changes: 5 additions & 1 deletion lib/pry/config/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,12 @@ class Default
exception_handler: proc {
Pry::DEFAULT_EXCEPTION_HANDLER
},
unrescued_exceptions: proc {
Pry::DEFAULT_UNRESCUED_EXCEPTIONS
},
exception_whitelist: proc {
Pry::DEFAULT_EXCEPTION_WHITELIST
warn 'Pry.config.exception_whitelist is deprecated, please use Pry.config.unrescued_exceptions instead.'
Pry::DEFAULT_UNRESCUED_EXCEPTIONS
},
hooks: proc {
Pry::DEFAULT_HOOKS
Expand Down
14 changes: 10 additions & 4 deletions lib/pry/exceptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def self.===(exception)
# Don't catch signals (particularly not SIGTERM) as these are unlikely
# to be intended for pry itself. We should also make sure that
# Kernel#exit works.
when *Pry.config.exception_whitelist
when *Pry.config.unrescued_exceptions
false
# All other exceptions will be caught.
else
Expand Down Expand Up @@ -57,9 +57,15 @@ def self.===(exception)
end

# Don't catch these exceptions
DEFAULT_EXCEPTION_WHITELIST = [SystemExit,
SignalException,
Pry::TooSafeException]
DEFAULT_UNRESCUED_EXCEPTIONS = [SystemExit,
SignalException,
Pry::TooSafeException]
DEFAULT_EXCEPTION_WHITELIST = DEFAULT_UNRESCUED_EXCEPTIONS
if Object.respond_to?(:deprecate_constant)
deprecate_constant :DEFAULT_EXCEPTION_WHITELIST
else
warn('DEFAULT_EXCEPTION_WHITELIST is deprecated and will be removed in a future version of Pry. Please use DEFAULT_UNRESCUED_EXCEPTIONS instead.')
end

# CommandErrors are caught by the REPL loop and displayed to the user. They
# indicate an exceptional condition that's fatal to the current command.
Expand Down
2 changes: 1 addition & 1 deletion lib/pry/pry_instance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ def handle_line(line, options)
# as an additional exception to be rescued explicitly.
#
# This workaround has a side effect: java exceptions specified
# in `Pry.config.exception_whitelist` are ignored.
# in `Pry.config.unrescued_exceptions` are ignored.
jruby_exceptions = []
if Helpers::Platform.jruby?
jruby_exceptions << Java::JavaLang::Exception
Expand Down
2 changes: 1 addition & 1 deletion spec/completion_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ module Baz
completer_test(self).call("[].size.chars")
end

it 'does not offer methods from blacklisted modules' do
it 'does not offer methods from restricted modules' do
require 'irb'
completer_test(self, nil, false).call("[].size.parse_printf_format")
end
Expand Down
21 changes: 0 additions & 21 deletions spec/exception_whitelist_spec.rb

This file was deleted.

6 changes: 3 additions & 3 deletions spec/hooks_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -366,8 +366,8 @@ class << o; attr_accessor :value; end
o = Pry::Config.new
o.great_escape = Class.new(StandardError)

old_ew = Pry.config.exception_whitelist
Pry.config.exception_whitelist << o.great_escape
old_ew = Pry.config.unrescued_exceptions
Pry.config.unrescued_exceptions << o.great_escape

array = [1, 2, 3, 4, 5]

Expand All @@ -387,7 +387,7 @@ class << o; attr_accessor :value; end
expect(array).to eq nil

# cleanup after test
Pry.config.exception_whitelist = old_ew
Pry.config.unrescued_exceptions = old_ew
end

describe "before_eval hook" do
Expand Down
19 changes: 19 additions & 0 deletions spec/unrescued_exceptions_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
require_relative 'helper'

describe "Pry.config.unrescued_exceptions" do
before do
@str_output = StringIO.new
end

it 'should rescue all exceptions NOT specified on unrescued_exceptions' do
expect(Pry.config.unrescued_exceptions.include?(NameError)).to eq false
expect { Pry.start(self, input: StringIO.new("raise NameError\nexit"), output: @str_output) }.not_to raise_error
end

it 'should NOT rescue exceptions specified on unrescued_exceptions' do
old_allowlist = Pry.config.unrescued_exceptions
Pry.config.unrescued_exceptions = [NameError]
expect { Pry.start(self, input: StringIO.new("raise NameError"), output: @str_output) }.to raise_error NameError
Pry.config.unrescued_exceptions = old_allowlist
end
end

0 comments on commit 4fd7307

Please sign in to comment.