From 84aa6fb652f31739b391b96abcfd395638fe6302 Mon Sep 17 00:00:00 2001 From: Robert Gleeson Date: Sat, 31 Aug 2013 20:54:52 +0200 Subject: [PATCH] extract Pry::RescuableException to lib/pry/rescuable_exception.rb --- lib/pry.rb | 31 +++++-------------------------- lib/pry/rescuable_exception.rb | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+), 26 deletions(-) create mode 100644 lib/pry/rescuable_exception.rb diff --git a/lib/pry.rb b/lib/pry.rb index 967e33bf..04aedcb6 100644 --- a/lib/pry.rb +++ b/lib/pry.rb @@ -1,13 +1,13 @@ # (C) John Mair (banisterfiend) 2013 # MIT License # - require 'pp' -require 'pry/helpers/base_helpers' -require 'pry/input_lock' -require 'pry/hooks' - class Pry + require 'pry/input_lock' + require 'pry/rescuable_exception' + require 'pry/helpers/base_helpers' + require 'pry/hooks' + # The default hooks - display messages when beginning and ending Pry sessions. DEFAULT_HOOKS = Pry::Hooks.new.add_hook(:before_session, :default) do |out, target, _pry_| next if _pry_.quiet? @@ -143,27 +143,6 @@ class Pry # your process has changed directory since boot. [Issue #675] INITIAL_PWD = Dir.pwd - # As a REPL, we often want to catch any unexpected exceptions that may have - # been raised; however we don't want to go overboard and prevent the user - # from exiting Pry when they want to. - module RescuableException - def self.===(exception) - case exception - # Catch when the user hits ^C (Interrupt < SignalException), and assume - # that they just wanted to stop the in-progress command (just like bash etc.) - when Interrupt - true - # 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 - false - # All other exceptions will be caught. - else - true - end - end - end - # An Exception Tag (cf. Exceptional Ruby) that instructs Pry to show the error in # a more user-friendly manner. This should be used when the exception happens within # Pry itself as a direct consequence of the user typing something wrong. diff --git a/lib/pry/rescuable_exception.rb b/lib/pry/rescuable_exception.rb new file mode 100644 index 00000000..34a11369 --- /dev/null +++ b/lib/pry/rescuable_exception.rb @@ -0,0 +1,20 @@ +# As a REPL, we often want to catch any unexpected exceptions that may have +# been raised; however we don't want to go overboard and prevent the user +# from exiting Pry when they want to. +module Pry::RescuableException + def self.===(exception) + case exception + # Catch when the user hits ^C (Interrupt < SignalException), and assume + # that they just wanted to stop the in-progress command (just like bash etc.) + when Interrupt + true + # 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 + false + # All other exceptions will be caught. + else + true + end + end +end