Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

version 0.2.0 release

all pry sessions get enter-exception by default
* post_mortem is off by default, turned on via a EE.post_mortem!
* inline is off by default, turned on via a EE.inline!
* now using cat --ex when intercepting exception rather than 'whereami'
  • Loading branch information...
commit 99bce4f8c2d2eb0af64f8eccbe4a55aefc6bfd35 1 parent e4749d7
John Mair banister authored
12 Rakefile
View
@@ -56,7 +56,17 @@ end
desc "Run example C inline"
task :example_c_inline do
- sh "pry-shim ruby -I#{direc}/lib/ #{direc}/examples/example_c_inline.rb "
+ sh "ruby -I#{direc}/lib/ #{direc}/examples/example_c_inline.rb "
+end
+
+desc "Run example C wrap"
+task :example_c_wrap do
+ sh "ruby -I#{direc}/lib/ #{direc}/examples/example_c_wrap.rb "
+end
+
+desc "Run example post mortem"
+task :example_post_mortem do
+ sh "ruby -I#{direc}/lib/ #{direc}/examples/example_post_mortem.rb "
end
task :default => :test
7 examples/example_c_inline.rb
View
@@ -5,7 +5,12 @@
require 'pry-exception_explorer'
-PryExceptionExplorer.enabled = true
+EE.inline!
+
+# we need to fine tune intercept when intercepting C exceptions
+# otherwise we could be intercepting exceptions internal to rubygems
+# and god knows what else...
+EE.intercept(ZeroDivisionError)
def alpha
name = "john"
2  examples/example_inline.rb
View
@@ -5,7 +5,7 @@
require 'pry-exception_explorer'
-PryExceptionExplorer.enabled = true
+EE.inline!
PryExceptionExplorer.intercept(ArgumentError)
def alpha
36 lib/pry-exception_explorer.rb
View
@@ -25,32 +25,24 @@ class << self
# @return [Boolean] Whether exceptions are to be intercepted
# inline (at the raise site).
- attr_reader :inline
+ attr_accessor :inline
# @return [Boolean] Whether exceptions are to be auto-rescued
# if they would terminate the program.
- attr_reader :post_mortem
+ attr_accessor :post_mortem
# @return [Boolean] Holds the previous value of `EE.inline`
attr_accessor :old_inline_state
- def inline=(v)
- self.enabled = true if v
- @inline = v
- end
-
- def post_mortem=(v)
- self.enabled = true if v
- @post_mortem = v
- end
-
- # Ensure exceptions are intercepted at the raise site.
+ # Ensure exceptions are intercepted at the raise site, and enable EE.
def inline!
+ self.enabled = true
self.inline = true
end
- # Ensure exceptions are intercepted if they would terminate the program.
+ # Ensure exceptions are intercepted if they would terminate the program, and enable EE.
def post_mortem!
+ self.enabled = true
self.post_mortem = true
end
@@ -214,14 +206,18 @@ def setup_exception_context(ex, _pry_, options={})
# @option options [Boolean] :inline Whether the exception is being
# entered inline (i.e within the `raise` method itself)
def enter_exception(ex, options={})
- hooks = Pry.config.hooks.dup.add_hook(:before_session, :set_exception_flag) do |_, _, _pry_|
+ hooks = Pry.config.hooks.dup
+ hooks.delete_hook(:before_session, :default)
+ hooks.add_hook(:before_session, :set_exception_flag) do |_, _, _pry_|
setup_exception_context(ex, _pry_, options)
end.add_hook(:before_session, :manage_intercept_recurse) do
PryExceptionExplorer.intercept_object.disable! if PryExceptionExplorer.inline? && !PryExceptionExplorer.intercept_object.intercept_recurse?
end.add_hook(:after_session, :manage_intercept_recurse) do
PryExceptionExplorer.intercept_object.enable! if !PryExceptionExplorer.intercept_object.active?
+ end.add_hook(:before_session, :display_exception) do |_, _, _pry_|
+ _pry_.run_command "cat --ex"
end
-
+
Pry.start binding, :call_stack => ex.exception_call_stack, :hooks => hooks
end
@@ -253,17 +249,15 @@ def init
end
end
-# Add a hook to properly setup EE for correct exception behaviour inside a pry session
+# Set up enter-exception style exception handling by default for pry sessions
Pry.config.hooks.add_hook(:before_session, :try_enable_exception_explorer) do
PryExceptionExplorer.enabled = true
PryExceptionExplorer.old_inline_state = PryExceptionExplorer.inline
PryExceptionExplorer.inline = false
-end
-
-Pry.config.hooks.add_hook(:after_session, :restore_inline_state) do
+end.add_hook(:after_session, :restore_inline_state) do
PryExceptionExplorer.inline = PryExceptionExplorer.old_inline_state
end
-
+
# Bring in commands
Pry.config.commands.import PryExceptionExplorer::Commands
5 lib/pry-exception_explorer/core_ext.rb
View
@@ -34,11 +34,10 @@ def exception(*args, &block)
if PryExceptionExplorer.enabled? &&
PryExceptionExplorer.should_intercept_exception?(binding.of_caller(1), self) &&
!caller.any? { |t| t.include?("raise") } && !exception_call_stack
-
- ex = old_exception(*args, &block)
+ ex = old_exception(*args, &block)
ex.exception_call_stack = binding.callers.drop(1)
- ex.set_backtrace(caller.drop(1)) if !ex.backtrace
+ ex.set_backtrace(caller) if !ex.backtrace
PryExceptionExplorer.amend_exception_call_stack!(ex)
ex.should_intercept = true
2  lib/pry-exception_explorer/version.rb
View
@@ -1,3 +1,3 @@
module PryExceptionExplorer
- VERSION = "0.2.0pre4"
+ VERSION = "0.2.0"
end
6 pry-exception_explorer.gemspec
View
@@ -2,11 +2,11 @@
Gem::Specification.new do |s|
s.name = "pry-exception_explorer"
- s.version = "0.2.0pre4"
+ s.version = "0.2.0"
- s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["John Mair (banisterfiend)"]
- s.date = "2012-09-30"
+ s.date = "2012-10-04"
s.description = "Enter the context of exceptions"
s.email = "jrmair@gmail.com"
s.executables = ["pry-shim"]
145 test/test_inline_exceptions.rb
View
@@ -4,10 +4,11 @@
# globally accessible state
O = OpenStruct.new
-PryExceptionExplorer.inline!
+
prev_intercept_state = PryExceptionExplorer.intercept_object
+PryExceptionExplorer.inline!
PryExceptionExplorer.enabled = true
describe PryExceptionExplorer do
@@ -77,36 +78,37 @@
EE.intercept_object = old
end
- describe "intercept_recurse" do
- it 'should NOT allow recursive (in-session) interceptions by default' do
- EE.intercept { |frame, ex| frame.klass == Toad }
-
- redirect_pry_io(InputTester.new("O.before_self = self",
- "Ratty.new.ratty",
- "O.after_self = self",
- "continue-exception",
- "continue-exception")) do
- Ratty.new.ratty
- end
-
- O.before_self.should == O.after_self
- end
-
- it 'should allow recursive (in-session) interceptions when :intercept_recurse => true' do
- EE.intercept { |frame, ex| frame.klass == Toad }.intercept_recurse(true)
-
- redirect_pry_io(InputTester.new("O.before_self = self",
- "Ratty.new.ratty",
- "O.after_self = self",
- "continue-exception",
- "continue-exception")) do
- Ratty.new.ratty
- end
-
- O.before_self.should.not == O.after_self
- end
-
- end
+ # * DEPRECATED * this test is no longer relevant as in-session exception handling is now restricted to enter-exception style
+ #
+ # describe "intercept_recurse" do
+ # it 'should NOT allow recursive (in-session) interceptions by default' do
+ # EE.intercept { |frame, ex| frame.klass == Toad }
+
+ # redirect_pry_io(InputTester.new("O.before_self = self",
+ # "Ratty.new.ratty",
+ # "O.after_self = self",
+ # "continue-exception",
+ # "continue-exception")) do
+ # Ratty.new.ratty
+ # end
+
+ # O.before_self.should == O.after_self
+ # end
+
+ # it 'should allow recursive (in-session) interceptions when :intercept_recurse => true' do
+ # EE.intercept { |frame, ex| frame.klass == Toad }.intercept_recurse(true)
+
+ # redirect_pry_io(InputTester.new("O.before_self = self",
+ # "Ratty.new.ratty",
+ # "O.after_self = self",
+ # "continue-exception",
+ # "continue-exception")) do
+ # Ratty.new.ratty
+ # end
+
+ # O.before_self.should.not == O.after_self
+ # end
+ # end
describe "skip" do
it 'should skip first frame with :skip => 1' do
@@ -179,9 +181,38 @@
O.method_name.should == :toad
end
end
+
+ describe "resetting inline EE state when leaving session" do
+
+ before do
+ Pry.config.hooks.add_hook(:before_session, :try_enable_exception_explorer) do
+ PryExceptionExplorer.enabled = true
+ PryExceptionExplorer.old_inline_state = PryExceptionExplorer.inline
+ PryExceptionExplorer.inline = false
+ end.add_hook(:after_session, :restore_inline_state) do
+ PryExceptionExplorer.inline = PryExceptionExplorer.old_inline_state
+ end
+ end
- describe "special case exception-only syntax" do
+ after do
+ Pry.config.hooks.delete_hook(:before_session, :try_enable_exception_explorer)
+ Pry.config.hooks.delete_hook(:after_session, :restore_inline_state)
+ end
+ it 'should have EE.inline set to false inside a session, and true outside the session' do
+ EE.intercept(Exception)
+ EE.inline!
+ redirect_pry_io(InputTester.new("O.in_session_inline_state = EE.inline",
+ "continue-exception")) do
+ raise "The children were crying, dreaming of the open beaks of dying birds."
+ end
+
+ O.in_session_inline_state.should == false
+ EE.inline.should == true
+ end
+ end
+
+ describe "special case exception-only syntax" do
describe "single exception" do
it 'should intercept provided exceptions when given parameters (and no block)' do
my_error = Class.new(StandardError)
@@ -384,30 +415,32 @@
PryStackExplorer.frame_managers(O._pry_).count.should == 0
end
- describe "nested exceptions" do
- it 'Each successive exception interception should be managed by its own pry instance and have its own call-stack' do
- EE.intercept { |frame, ex| frame.prev.prev.method_name == :ratty }
-
- redirect_pry_io(InputTester.new(
- "O.first_stack_count = PryStackExplorer.frame_managers(_pry_).count",
- "O._pry_ = _pry_",
- "EE.intercept(ArgumentError)",
- "raise ArgumentError",
- "O._pry_2 = _pry_",
- "O.second_stack_count = PryStackExplorer.frame_managers(_pry_).count",
- "continue-exception",
- "continue-exception"), StringIO.new) do
- Ratty.new.ratty
- end
-
- O._pry_.should.not == O._pry_2
- O.first_stack_count.should == 1
- O.second_stack_count.should == 1
- PryStackExplorer.frame_managers(O._pry_).count.should == 0
- PryStackExplorer.frame_managers(O._pry_2).count.should == 0
- end
-
- end
+ # * DEPRECATED * this test is no longer relevant as in-session exception handling is now restricted to enter-exception style
+ #
+ # describe "nested exceptions" do
+ # it 'Each successive exception interception should be managed by its own pry instance and have its own call-stack' do
+ # EE.intercept { |frame, ex| frame.prev.prev.method_name == :ratty }
+
+ # redirect_pry_io(InputTester.new(
+ # "O.first_stack_count = PryStackExplorer.frame_managers(_pry_).count",
+ # "O._pry_ = _pry_",
+ # "EE.intercept(ArgumentError)",
+ # "raise ArgumentError",
+ # "O._pry_2 = _pry_",
+ # "O.second_stack_count = PryStackExplorer.frame_managers(_pry_).count",
+ # "continue-exception",
+ # "continue-exception"), StringIO.new) do
+ # Ratty.new.ratty
+ # end
+
+ # O._pry_.should.not == O._pry_2
+ # O.first_stack_count.should == 1
+ # O.second_stack_count.should == 1
+ # PryStackExplorer.frame_managers(O._pry_).count.should == 0
+ # PryStackExplorer.frame_managers(O._pry_2).count.should == 0
+ # end
+
+ # end
describe "exit-exception" do
it 'should exit session and raise exception' do
2  test/test_wrapped_exceptions.rb
View
@@ -112,7 +112,7 @@ class << o; attr_accessor :ex, :pry_bt; self; end.class_eval { define_method(:ra
PryExceptionExplorer.intercept { true }
x = :no_exception_raised
- redirect_pry_io(InputTester.new("exit-exception"), $stdout) do
+ redirect_pry_io(InputTester.new("exit-exception"), StringIO.new) do
PryExceptionExplorer.wrap do
Ratty.new.ratty
end
Please sign in to comment.
Something went wrong with that request. Please try again.