pry-exception_explorer 0.1.3.5 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
@@ -2,8 +2,18 @@
|
|
2
2
|
class Exception
|
3
3
|
NoContinuation = Class.new(StandardError)
|
4
4
|
|
5
|
+
# @return [Continuation] The continuation object for the exception.
|
6
|
+
# Invoking this continuation will allow the program to continue
|
7
|
+
# from the point the exception was raised.
|
5
8
|
attr_accessor :continuation
|
9
|
+
|
10
|
+
# @return [Array<Binding>] The array of bindings that represent the
|
11
|
+
# call stack for the exception. This is navigable inside the Pry
|
12
|
+
# session with the `up` and `down` and `frame` commands.
|
6
13
|
attr_accessor :exception_call_stack
|
14
|
+
|
15
|
+
# @return [Boolean] Whether this exception should be intercepted.
|
16
|
+
# (Only relevant for wrapped exceptions).
|
7
17
|
attr_accessor :should_intercept
|
8
18
|
|
9
19
|
# This method enables us to continue an exception (using
|
@@ -28,47 +38,48 @@ class Object
|
|
28
38
|
exception = RuntimeError
|
29
39
|
end
|
30
40
|
|
31
|
-
if !PryExceptionExplorer.enabled?
|
32
|
-
if exception.is_a?(Exception) || (exception.is_a?(Class) && exception < Exception)
|
33
|
-
return super(*args)
|
34
|
-
elsif exception.nil?
|
35
|
-
if $!
|
36
|
-
return super($!)
|
37
|
-
else
|
38
|
-
return super(RuntimeError)
|
39
|
-
end
|
40
|
-
else
|
41
|
-
return super(*args)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
41
|
if exception.is_a?(Exception) || (exception.is_a?(Class) && exception < Exception)
|
46
|
-
if
|
47
|
-
ex = exception.exception(string)
|
42
|
+
if PryExceptionExplorer.enabled?
|
43
|
+
ex = string ? exception.exception(string) : exception.exception
|
48
44
|
else
|
49
|
-
|
45
|
+
return super(*args)
|
50
46
|
end
|
51
47
|
elsif exception.nil?
|
52
48
|
if $!
|
53
|
-
|
49
|
+
if PryExceptionExplorer.enabled?
|
50
|
+
ex = $!.exception
|
51
|
+
else
|
52
|
+
return super($!)
|
53
|
+
end
|
54
54
|
else
|
55
|
-
|
55
|
+
if PryExceptionExplorer.enabled?
|
56
|
+
ex = RuntimeError.exception
|
57
|
+
else
|
58
|
+
return super(RuntimeError)
|
59
|
+
end
|
56
60
|
end
|
57
61
|
else
|
58
|
-
|
62
|
+
if PryExceptionExplorer.enabled?
|
63
|
+
ex = RuntimeError.exception
|
64
|
+
else
|
65
|
+
return super(*args)
|
66
|
+
end
|
59
67
|
end
|
60
68
|
|
61
69
|
ex.set_backtrace(array ? array : caller)
|
62
70
|
|
63
71
|
intercept_object = PryExceptionExplorer.intercept_object
|
64
72
|
|
73
|
+
# FIXME: CodeRay stuff is a hack because CodeRay generates a bunch of
|
74
|
+
# exceptions that would cause EE to infiniloop on
|
75
|
+
# intercept(Exception), find a better solution.
|
65
76
|
if PryExceptionExplorer.should_intercept_exception?(binding.of_caller(1), ex) &&
|
66
77
|
binding.of_caller(1).eval('[__method__, self.to_s]') != [:make_plugin_hash, "CodeRay::Encoders"]
|
67
78
|
|
68
79
|
ex.exception_call_stack = binding.callers.tap { |v| v.shift(1 + intercept_object.skip_num) }
|
69
80
|
PryExceptionExplorer.amend_exception_call_stack!(ex)
|
70
81
|
|
71
|
-
ex.should_intercept
|
82
|
+
ex.should_intercept = true
|
72
83
|
|
73
84
|
if !PryExceptionExplorer.wrap_active?
|
74
85
|
retval = PryExceptionExplorer.enter_exception(ex, :inline => true)
|
@@ -136,11 +136,14 @@ module PryExceptionExplorer
|
|
136
136
|
def amend_exception_call_stack!(ex)
|
137
137
|
call_stack = ex.exception_call_stack
|
138
138
|
|
139
|
+
# skip_until
|
139
140
|
if intercept_object.skip_until_block
|
140
141
|
idx = call_stack.each_with_index.find_index do |frame, idx|
|
141
142
|
intercept_object.skip_until_block.call(LazyFrame.new(frame, idx, call_stack))
|
142
143
|
end
|
143
144
|
call_stack = call_stack.drop(idx) if idx
|
145
|
+
|
146
|
+
# skip_while
|
144
147
|
elsif intercept_object.skip_while_block
|
145
148
|
idx = call_stack.each_with_index.find_index do |frame, idx|
|
146
149
|
intercept_object.skip_while_block.call(LazyFrame.new(frame, idx, call_stack)) == false
|
@@ -173,7 +176,7 @@ module PryExceptionExplorer
|
|
173
176
|
# entered inline (i.e within the `raise` method itself)
|
174
177
|
def enter_exception(ex, options={})
|
175
178
|
hooks = Pry.config.hooks.dup.add_hook(:before_session, :set_exception_flag) do |_, _, _pry_|
|
176
|
-
setup_exception_context(ex, _pry_, options)
|
179
|
+
setup_exception_context(ex, _pry_, options)
|
177
180
|
end.add_hook(:before_session, :manage_intercept_recurse) do
|
178
181
|
PryExceptionExplorer.intercept_object.disable! if !PryExceptionExplorer.intercept_object.intercept_recurse?
|
179
182
|
end.add_hook(:after_session, :manage_intercept_recurse) do
|
@@ -182,7 +185,6 @@ module PryExceptionExplorer
|
|
182
185
|
|
183
186
|
# Pry.load_plugins
|
184
187
|
# binding.pry # if we have this here and step through with pry-nav sometimes we get segfaults :/
|
185
|
-
# end
|
186
188
|
|
187
189
|
Pry.start self, :call_stack => ex.exception_call_stack, :hooks => hooks
|
188
190
|
end
|
@@ -2,19 +2,19 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = "pry-exception_explorer"
|
5
|
-
s.version = "0.1.
|
5
|
+
s.version = "0.1.4"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["John Mair (banisterfiend)"]
|
9
|
-
s.date = "2012-02-
|
9
|
+
s.date = "2012-02-08"
|
10
10
|
s.description = "Enter the context of exceptions"
|
11
11
|
s.email = "jrmair@gmail.com"
|
12
|
-
s.files = [".gemtest", ".gitignore", ".travis.yml", ".yardopts", "CHANGELOG", "Gemfile", "LICENSE", "README.md", "Rakefile", "examples/example_c_inline.rb", "examples/example_inline.rb", "examples/example_wrap.rb", "lib/pry-exception_explorer.rb", "lib/pry-exception_explorer/cli.rb", "lib/pry-exception_explorer/commands.rb", "lib/pry-exception_explorer/core_ext.rb", "lib/pry-exception_explorer/intercept.rb", "lib/pry-exception_explorer/lazy_frame.rb", "lib/pry-exception_explorer/shim_builder.rb", "lib/pry-exception_explorer/version.rb", "pry-exception_explorer.gemspec", "test/helper.rb", "test/test_exceptions_in_pry.rb", "test/test_inline_exceptions.rb", "test/test_wrapped_exceptions.rb"]
|
12
|
+
s.files = [".gemtest", ".gitignore", ".travis.yml", ".yardopts", "CHANGELOG", "Gemfile", "LICENSE", "README.md", "Rakefile", "examples/example_c_inline.rb", "examples/example_inline.rb", "examples/example_wrap.rb", "lib/pry-exception_explorer.rb", "lib/pry-exception_explorer/cli.rb", "lib/pry-exception_explorer/commands.rb", "lib/pry-exception_explorer/core_ext.rb", "lib/pry-exception_explorer/intercept.rb", "lib/pry-exception_explorer/lazy_frame.rb", "lib/pry-exception_explorer/shim_builder.rb", "lib/pry-exception_explorer/version.rb", "pry-exception_explorer.gemspec", "test/helper.rb", "test/test_exceptions_in_pry.rb", "test/test_inline_exceptions.rb", "test/test_raise.rb", "test/test_wrapped_exceptions.rb"]
|
13
13
|
s.homepage = "https://github.com/banister/pry-exception_explorer"
|
14
14
|
s.require_paths = ["lib"]
|
15
|
-
s.rubygems_version = "1.8.
|
15
|
+
s.rubygems_version = "1.8.15"
|
16
16
|
s.summary = "Enter the context of exceptions"
|
17
|
-
s.test_files = ["test/helper.rb", "test/test_exceptions_in_pry.rb", "test/test_inline_exceptions.rb", "test/test_wrapped_exceptions.rb"]
|
17
|
+
s.test_files = ["test/helper.rb", "test/test_exceptions_in_pry.rb", "test/test_inline_exceptions.rb", "test/test_raise.rb", "test/test_wrapped_exceptions.rb"]
|
18
18
|
|
19
19
|
if s.respond_to? :specification_version then
|
20
20
|
s.specification_version = 3
|
data/test/test_raise.rb
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe PryExceptionExplorer do
|
4
|
+
|
5
|
+
describe "normal raise behaviour (EE.enabled = false)" do
|
6
|
+
before do
|
7
|
+
EE.enabled = false
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'should raise the exception that was raised' do
|
11
|
+
begin
|
12
|
+
raise ArgumentError
|
13
|
+
rescue => ex
|
14
|
+
ex.is_a?(ArgumentError).should == true
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should keep message' do
|
19
|
+
begin
|
20
|
+
raise ArgumentError, "hello"
|
21
|
+
rescue => ex
|
22
|
+
ex.message.should == "hello"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should implicitly re-raise rescued exceptione' do
|
27
|
+
begin
|
28
|
+
raise ArgumentError
|
29
|
+
rescue => ex
|
30
|
+
begin
|
31
|
+
raise
|
32
|
+
rescue => ex2
|
33
|
+
ex2.is_a?(ArgumentError).should == true
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should implicitly raise RuntimeError (when not inside rescue)' do
|
39
|
+
begin
|
40
|
+
raise
|
41
|
+
rescue => ex
|
42
|
+
ex.is_a?(RuntimeError).should == true
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'should re-raise raised rescued exception' do
|
47
|
+
begin
|
48
|
+
raise ArgumentError
|
49
|
+
rescue => ex
|
50
|
+
begin
|
51
|
+
raise ex
|
52
|
+
rescue
|
53
|
+
ex.is_a?(ArgumentError).should == true
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "raise behaviour AFTER interception (EE.enabled = true)" do
|
60
|
+
before do
|
61
|
+
Pry.config.hooks.add_hook(:when_started, :save_caller_bindings, WhenStartedHook)
|
62
|
+
Pry.config.hooks.add_hook(:after_session, :delete_frame_manager, AfterSessionHook)
|
63
|
+
|
64
|
+
EE.enabled = true
|
65
|
+
EE.intercept(ArgumentError)
|
66
|
+
EE.wrap_active = false
|
67
|
+
Pry.config.input = StringIO.new("exit-all\n")
|
68
|
+
# Pry.config.input = Readline
|
69
|
+
# Pry.config.output = $stdout
|
70
|
+
end
|
71
|
+
|
72
|
+
after do
|
73
|
+
Pry.config.hooks.delete_hook(:when_started, :save_caller_bindings)
|
74
|
+
Pry.config.hooks.delete_hook(:after_session, :delete_frame_manager)
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'should raise the exception that was raised' do
|
78
|
+
begin
|
79
|
+
raise ArgumentError
|
80
|
+
rescue => ex
|
81
|
+
ex.is_a?(ArgumentError).should == true
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'should keep message' do
|
86
|
+
begin
|
87
|
+
raise ArgumentError, "hello"
|
88
|
+
rescue => ex
|
89
|
+
ex.message.should == "hello"
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'should implicitly re-raise rescued exceptione' do
|
94
|
+
begin
|
95
|
+
raise ArgumentError
|
96
|
+
rescue => ex
|
97
|
+
begin
|
98
|
+
raise
|
99
|
+
rescue => ex2
|
100
|
+
ex2.is_a?(ArgumentError).should == true
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'should implicitly raise RuntimeError (when not inside rescue)' do
|
106
|
+
begin
|
107
|
+
raise
|
108
|
+
rescue => ex
|
109
|
+
ex.is_a?(RuntimeError).should == true
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
it 'should re-raise raised rescued exception' do
|
114
|
+
begin
|
115
|
+
raise ArgumentError
|
116
|
+
rescue => ex
|
117
|
+
begin
|
118
|
+
raise ex
|
119
|
+
rescue
|
120
|
+
ex.is_a?(ArgumentError).should == true
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pry-exception_explorer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-02-
|
12
|
+
date: 2012-02-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: pry-stack_explorer
|
16
|
-
requirement: &
|
16
|
+
requirement: &70190810463180 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70190810463180
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: bacon
|
27
|
-
requirement: &
|
27
|
+
requirement: &70190810462680 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 1.1.0
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70190810462680
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rake
|
38
|
-
requirement: &
|
38
|
+
requirement: &70190810462080 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: '0.9'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70190810462080
|
47
47
|
description: Enter the context of exceptions
|
48
48
|
email: jrmair@gmail.com
|
49
49
|
executables: []
|
@@ -74,6 +74,7 @@ files:
|
|
74
74
|
- test/helper.rb
|
75
75
|
- test/test_exceptions_in_pry.rb
|
76
76
|
- test/test_inline_exceptions.rb
|
77
|
+
- test/test_raise.rb
|
77
78
|
- test/test_wrapped_exceptions.rb
|
78
79
|
homepage: https://github.com/banister/pry-exception_explorer
|
79
80
|
licenses: []
|
@@ -103,4 +104,5 @@ test_files:
|
|
103
104
|
- test/helper.rb
|
104
105
|
- test/test_exceptions_in_pry.rb
|
105
106
|
- test/test_inline_exceptions.rb
|
107
|
+
- test/test_raise.rb
|
106
108
|
- test/test_wrapped_exceptions.rb
|