mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
Update clearer terminologies
Deprecate Pry.config.exception_whitelist, use Pry.config.unrescued_exceptions instead. Deprecate Pry::DEFAULT_EXCEPTION_WHITELIST, use Pry::DEFAULT_UNRESCUED_EXCEPTIONS instead. What white / black means are not clear, use clearer terminologies.
This commit is contained in:
parent
e138cb3d0a
commit
d12ce06a7f
8 changed files with 40 additions and 32 deletions
|
@ -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.
|
||||
|
|
|
@ -32,8 +32,12 @@ class Pry
|
|||
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
|
||||
|
|
|
@ -13,7 +13,7 @@ class Pry
|
|||
# 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
|
||||
|
@ -57,9 +57,15 @@ class Pry
|
|||
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.
|
||||
|
|
|
@ -310,7 +310,7 @@ class Pry
|
|||
# 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
|
||||
|
|
|
@ -213,7 +213,7 @@ describe Pry::InputCompleter do
|
|||
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
|
||||
|
|
|
@ -1,21 +0,0 @@
|
|||
require_relative 'helper'
|
||||
|
||||
describe "Pry.config.exception_whitelist" do
|
||||
before do
|
||||
@str_output = StringIO.new
|
||||
end
|
||||
|
||||
it 'should rescue all exceptions NOT specified on whitelist' do
|
||||
expect(Pry.config.exception_whitelist.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 whitelist' do
|
||||
old_whitelist = Pry.config.exception_whitelist
|
||||
Pry.config.exception_whitelist = [NameError]
|
||||
expect { Pry.start(self, input: StringIO.new("raise NameError"), output: @str_output) }.to raise_error NameError
|
||||
Pry.config.exception_whitelist = old_whitelist
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -366,8 +366,8 @@ describe Pry::Hooks do
|
|||
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]
|
||||
|
||||
|
@ -387,7 +387,7 @@ describe Pry::Hooks do
|
|||
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
|
||||
|
|
19
spec/unrescued_exceptions_spec.rb
Normal file
19
spec/unrescued_exceptions_spec.rb
Normal file
|
@ -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
|
Loading…
Reference in a new issue