pry-exception_explorer 0.2.0pre1 → 0.2.0pre2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -62,31 +62,15 @@ module PryExceptionExplorer
62
62
  !!local_hash[:enabled]
63
63
  end
64
64
 
65
- # @param [Boolean] v Whether to intercept only those exceptions that bubble out of
66
- # `EE.wrap` block.
67
- def wrap_active=(v)
68
- local_hash[:wrap_active] = v
69
- end
70
-
71
- # @return [Boolean] Whether to intercept only those exceptions that bubble out of
72
- # `EE.wrap` block.
73
- def wrap_active
74
- !!local_hash[:wrap_active]
75
- end
76
-
77
- alias_method :wrap_active?, :wrap_active
78
65
  alias_method :enabled?, :enabled
79
66
 
80
-
81
67
  # Wrap the provided block - intercepting all exceptions
82
68
  # that bubble out, provided they satisfy the
83
69
  # assertion in `PryExceptionExplorer.intercept`.
84
70
  # @yield The block to wrap.
85
71
  def wrap
86
- old_enabled, old_wrap_active = enabled, wrap_active
87
- old_inline = inline
72
+ old_enabled, old_inline = enabled, inline
88
73
  self.enabled = true
89
- self.wrap_active = true
90
74
  self.inline = false
91
75
  yield
92
76
  rescue Exception => ex
@@ -96,9 +80,8 @@ module PryExceptionExplorer
96
80
  raise ex
97
81
  end
98
82
  ensure
99
- self.enabled = old_enabled
100
- self.wrap_active = old_wrap_active
101
- self.inline = old_inline
83
+ self.enabled = old_enabled
84
+ self.inline = old_inline
102
85
  end
103
86
 
104
87
  # This method allows the user to assert the situations where an
@@ -222,16 +205,17 @@ module PryExceptionExplorer
222
205
 
223
206
  # Set initial state
224
207
  def init
225
- PryExceptionExplorer.post_mortem = true
208
+
209
+ # enable EE
226
210
  PryExceptionExplorer.enabled = true
227
-
228
- # disable by default (intercept exceptions inline)
229
- PryExceptionExplorer.wrap_active = true
211
+
212
+ # auto-start sessions on exceptions that would kill the program
213
+ PryExceptionExplorer.post_mortem = true
230
214
 
231
215
  # default is to capture all exceptions
232
- PryExceptionExplorer.intercept { true }
216
+ PryExceptionExplorer.intercept(Exception)
233
217
 
234
- # disable by default
218
+ # disable inline sessions by defulat
235
219
  PryExceptionExplorer.inline = false
236
220
  at_exit do
237
221
  ex = $!
@@ -250,7 +234,6 @@ end
250
234
 
251
235
  # Add a hook to enable EE when invoked via `pry` executable
252
236
  Pry.config.hooks.add_hook(:when_started, :try_enable_exception_explorer) do
253
- PryExceptionExplorer.wrap_active = true
254
237
  PryExceptionExplorer.enabled = true
255
238
  PryExceptionExplorer.inline = false
256
239
  end
@@ -18,8 +18,8 @@ module PryExceptionExplorer
18
18
  _pry_.last_exception
19
19
  end
20
20
 
21
- def enterable_exception?
22
- PryExceptionExplorer.enabled && last_exception && last_exception.exception_call_stack
21
+ def enterable_exception?(ex=last_exception)
22
+ PryExceptionExplorer.enabled && ex && ex.exception_call_stack
23
23
  end
24
24
 
25
25
  def inline_exception?
@@ -46,21 +46,34 @@ module PryExceptionExplorer
46
46
  BANNER
47
47
 
48
48
  def process
49
- if enterable_exception?
50
- PryStackExplorer.create_and_push_frame_manager(last_exception.exception_call_stack, _pry_)
51
- PryExceptionExplorer.setup_exception_context(last_exception, _pry_)
49
+ ex = extract_exception
50
+ if enterable_exception?(ex)
51
+ PryStackExplorer.create_and_push_frame_manager(ex.exception_call_stack, _pry_)
52
+ PryExceptionExplorer.setup_exception_context(ex, _pry_)
52
53
 
53
54
  # have to use _pry_.run_command instead of 'run' here as
54
55
  # 'run' works on the current target which hasnt been updated
55
56
  # yet, whereas _pry_.run_command operates on the newly
56
57
  # updated target (the context of the exception)
57
58
  _pry_.run_command "whereami"
58
- elsif last_exception
59
- raise Pry::CommandError, "Current exception can't be entered! (perhaps a C exception)"
59
+ elsif ex
60
+ raise Pry::CommandError, "Current exception can't be entered! (perhaps an internal exception)"
60
61
  else
61
62
  raise Pry::CommandError, "No exception to enter!"
62
63
  end
63
64
  end
65
+
66
+ def extract_exception
67
+ if !arg_string.empty?
68
+ ex = target.eval(arg_string)
69
+ raise if !ex.is_a?(Exception)
70
+ ex
71
+ else
72
+ last_exception
73
+ end
74
+ rescue
75
+ raise Pry::CommandError, "Parameter must be a valid exception object."
76
+ end
64
77
  end
65
78
 
66
79
  create_command "exit-exception", "Leave the context of the current exception." do
@@ -31,7 +31,6 @@ class Exception
31
31
  alias_method :old_exception, :exception
32
32
 
33
33
  def exception(*args, &block)
34
- $e = binding.callers.drop(1)
35
34
  if PryExceptionExplorer.enabled? &&
36
35
  PryExceptionExplorer.should_intercept_exception?(binding.of_caller(1), self) &&
37
36
  !caller.any? { |t| t.include?("raise") } && !exception_call_stack
@@ -1,3 +1,3 @@
1
1
  module PryExceptionExplorer
2
- VERSION = "0.2.0pre1"
2
+ VERSION = "0.2.0pre2"
3
3
  end
@@ -6,7 +6,6 @@ describe PryExceptionExplorer do
6
6
 
7
7
  before do
8
8
  PryExceptionExplorer.intercept { true }
9
- PryExceptionExplorer.wrap_active = true
10
9
  PryExceptionExplorer.enabled = true
11
10
  end
12
11
 
@@ -77,6 +76,19 @@ describe PryExceptionExplorer do
77
76
  O.method_name.should == :toad
78
77
  end
79
78
 
79
+ it "should be able to enter an explicitly provided exception (even if _ex_ has changed)" do
80
+ redirect_pry_io(InputTester.new("Ratty.new.ratty",
81
+ "ex = _ex_",
82
+ "AnotherException",
83
+ "enter-exception ex",
84
+ "O.method_name = __method__",
85
+ "exit", StringIO.new)) do
86
+ Pry.start
87
+ end
88
+
89
+ O.method_name.should == :toad
90
+ end
91
+
80
92
  it "should have access to exception's caller" do
81
93
  mock_pry("Ratty.new.ratty", "enter-exception", "show-stack", "exit").should =~ /toad.*?weasel.*?ratty/m
82
94
  end
@@ -4,8 +4,6 @@ require 'ostruct'
4
4
  # globally accessible state
5
5
  O = OpenStruct.new
6
6
 
7
- prev_wrap_state = PryExceptionExplorer.wrap_active
8
- PryExceptionExplorer.wrap_active = false
9
7
  PryExceptionExplorer.inline!
10
8
 
11
9
  prev_intercept_state = PryExceptionExplorer.intercept_object
@@ -15,7 +13,6 @@ PryExceptionExplorer.enabled = true
15
13
  describe PryExceptionExplorer do
16
14
 
17
15
  before do
18
- PryExceptionExplorer.wrap_active = false
19
16
  O.exception_intercepted = false
20
17
 
21
18
  # Ensure that when an exception is intercepted (a pry session
@@ -434,7 +431,6 @@ describe PryExceptionExplorer do
434
431
  end
435
432
 
436
433
  # restore to default
437
- PryExceptionExplorer.wrap_active = prev_wrap_state
438
434
  PryExceptionExplorer.intercept_object = prev_intercept_state
439
435
 
440
436
  Object.send(:remove_const, :O)
data/test/test_raise.rb CHANGED
@@ -63,10 +63,7 @@ describe PryExceptionExplorer do
63
63
 
64
64
  EE.enabled = true
65
65
  EE.intercept(ArgumentError)
66
- EE.wrap_active = false
67
66
  Pry.config.input = StringIO.new("exit-all\n")
68
- # Pry.config.input = Readline
69
- # Pry.config.output = $stdout
70
67
  end
71
68
 
72
69
  after do
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.2.0pre1
4
+ version: 0.2.0pre2
5
5
  prerelease: 5
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-09-29 00:00:00.000000000 Z
12
+ date: 2012-09-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: pry-stack_explorer
16
- requirement: &70293402053520 !ruby/object:Gem::Requirement
16
+ requirement: &70215832457180 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 0.4.6
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70293402053520
24
+ version_requirements: *70215832457180
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: bacon
27
- requirement: &70293401916160 !ruby/object:Gem::Requirement
27
+ requirement: &70215832456340 !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: *70293401916160
35
+ version_requirements: *70215832456340
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rake
38
- requirement: &70293401915540 !ruby/object:Gem::Requirement
38
+ requirement: &70215832455760 !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: *70293401915540
46
+ version_requirements: *70215832455760
47
47
  description: Enter the context of exceptions
48
48
  email: jrmair@gmail.com
49
49
  executables: