pry-rescue 0.15 → 0.16
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +24 -0
- data/lib/pry-rescue.rb +28 -5
- data/lib/pry-rescue/commands.rb +31 -1
- data/lib/pry-rescue/core_ext.rb +1 -1
- data/pry-rescue.gemspec +1 -1
- data/spec/commands_spec.rb +32 -0
- metadata +2 -2
data/README.md
CHANGED
@@ -75,6 +75,30 @@ end
|
|
75
75
|
Pry::rescue{ test }
|
76
76
|
```
|
77
77
|
|
78
|
+
cd-raise
|
79
|
+
========
|
80
|
+
|
81
|
+
If you've run some code in Pry, and an exception was raised, you can use the `cd-raise`
|
82
|
+
command:
|
83
|
+
|
84
|
+
```
|
85
|
+
[1] pry(main)> foo
|
86
|
+
RuntimeError: two
|
87
|
+
from a.rb:4:in `rescue in foo'
|
88
|
+
[2] pry(main)> cd-raise
|
89
|
+
From: a.rb @ line 4 Object#foo:
|
90
|
+
|
91
|
+
1: def foo
|
92
|
+
2: raise "one"
|
93
|
+
3: rescue => e
|
94
|
+
=> 4: raise "two"
|
95
|
+
5: end
|
96
|
+
|
97
|
+
[1] pry(main)>
|
98
|
+
```
|
99
|
+
|
100
|
+
To get back from `cd-raise` you can either type `<ctrl+d>` or `cd ..`.
|
101
|
+
|
78
102
|
cd-cause
|
79
103
|
========
|
80
104
|
|
data/lib/pry-rescue.rb
CHANGED
@@ -24,6 +24,11 @@ begin
|
|
24
24
|
rescue LoadError
|
25
25
|
end
|
26
26
|
|
27
|
+
# Ensure that any exceptions raised within pry are available
|
28
|
+
Pry.config.hooks.add_hook :before_session, :enable_rescuing do
|
29
|
+
Pry.enable_rescuing!
|
30
|
+
end
|
31
|
+
|
27
32
|
# PryRescue provides the ability to open a Pry shell whenever an unhandled exception is
|
28
33
|
# raised in your code.
|
29
34
|
#
|
@@ -104,11 +109,21 @@ class PryRescue
|
|
104
109
|
# @param [String] file the absolute path
|
105
110
|
# @return [Boolean]
|
106
111
|
def user_path?(file)
|
107
|
-
return
|
108
|
-
return
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
+
return true if current_path?(file)
|
113
|
+
return false if stdlib_path?(file) || gem_path?(file)
|
114
|
+
true
|
115
|
+
end
|
116
|
+
|
117
|
+
# Is this file definitely part of the codebase the user is working on?
|
118
|
+
#
|
119
|
+
# This function exists because sometimes Dir.pwd can be a gem_path?,
|
120
|
+
# and the user expects to be able to debug a gem when they're cd'd
|
121
|
+
# into it.
|
122
|
+
#
|
123
|
+
# @param [String] file the absolute path
|
124
|
+
# @return [Boolean]
|
125
|
+
def current_path?(file)
|
126
|
+
file.start_with?(Dir.pwd) && !file.match(%r(/vendor/))
|
112
127
|
end
|
113
128
|
|
114
129
|
# Is this path included in a gem?
|
@@ -125,6 +140,14 @@ class PryRescue
|
|
125
140
|
end
|
126
141
|
end
|
127
142
|
|
143
|
+
# Is this path in the ruby standard library?
|
144
|
+
#
|
145
|
+
# @param [String] file the absolute path
|
146
|
+
# @return [Boolean]
|
147
|
+
def stdlib_path?(file)
|
148
|
+
file.start_with?(RbConfig::CONFIG['libdir']) || %w( (eval) <internal:prelude> ).include?(file)
|
149
|
+
end
|
150
|
+
|
128
151
|
# Remove bindings that are part of Interception/Pry.rescue's internal
|
129
152
|
# event handling that happens as part of the exception hooking process.
|
130
153
|
#
|
data/lib/pry-rescue/commands.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Pry::Commands.create_command "cd-cause", "Move to the
|
1
|
+
Pry::Commands.create_command "cd-cause", "Move to the exception that caused this exception to happen" do
|
2
2
|
|
3
3
|
banner <<-BANNER
|
4
4
|
Usage: cd-cause
|
@@ -43,6 +43,36 @@ Pry::Commands.create_command "cd-cause", "Move to the previously raised exceptio
|
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
|
+
Pry::Commands.create_command "cd-raise", "Move to the point at which an exception was raised" do
|
47
|
+
banner <<-BANNER
|
48
|
+
Usage: cd-raise [_ex_]
|
49
|
+
|
50
|
+
Starts a new pry session at the point that the given exception was raised.
|
51
|
+
|
52
|
+
If no exception is given, defaults to _ex_, the most recent exception that
|
53
|
+
was raised by code you ran from within pry.
|
54
|
+
|
55
|
+
@example
|
56
|
+
|
57
|
+
[2] pry(main)> foo
|
58
|
+
RuntimeError: two
|
59
|
+
from /home/conrad/0/ruby/pry-rescue/a.rb:4:in `rescue in foo'
|
60
|
+
[3] pry(main)> cd-raise
|
61
|
+
|
62
|
+
1: def foo
|
63
|
+
2: raise "one"
|
64
|
+
3: rescue => e
|
65
|
+
=> 4: raise "two"
|
66
|
+
5: end
|
67
|
+
BANNER
|
68
|
+
|
69
|
+
def process
|
70
|
+
ex = target.eval(args.first || "_ex_")
|
71
|
+
raise Pry::CommandError, "No most recent exception" unless ex
|
72
|
+
Pry.rescued(ex)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
46
76
|
Pry::Commands.create_command "try-again", "Re-try the code that caused this exception" do
|
47
77
|
|
48
78
|
banner <<-BANNER
|
data/lib/pry-rescue/core_ext.rb
CHANGED
data/pry-rescue.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'pry-rescue'
|
3
|
-
s.version = '0.
|
3
|
+
s.version = '0.16'
|
4
4
|
s.summary = 'Open a pry session on any unhandled exceptions'
|
5
5
|
s.description = 'Allows you to wrap code in Pry::rescue{ } to open a pry session at any unhandled exceptions'
|
6
6
|
s.homepage = 'https://github.com/ConradIrwin/pry-rescue'
|
data/spec/commands_spec.rb
CHANGED
@@ -17,6 +17,38 @@ describe "pry-rescue commands" do
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
+
describe "cd-raise" do
|
21
|
+
it "should enter the context of an explicit exception" do
|
22
|
+
begin
|
23
|
+
b1 = binding
|
24
|
+
raise "original"
|
25
|
+
rescue => e1
|
26
|
+
b2 = binding
|
27
|
+
end
|
28
|
+
|
29
|
+
Pry.should_receive(:rescued).once.with{ |raised|
|
30
|
+
raised.should == e1
|
31
|
+
}
|
32
|
+
|
33
|
+
Pry.new.process_command 'cd-raise e1', '', binding
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should enter the context of _ex_ if no exception is given" do
|
37
|
+
begin
|
38
|
+
b1 = binding
|
39
|
+
raise "original"
|
40
|
+
rescue => _ex_
|
41
|
+
b2 = binding
|
42
|
+
end
|
43
|
+
|
44
|
+
Pry.should_receive(:rescued).once.with{ |raised|
|
45
|
+
raised.should == _ex_
|
46
|
+
}
|
47
|
+
|
48
|
+
Pry.new.process_command 'cd-raise', '', binding
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
20
52
|
describe "cd-cause" do
|
21
53
|
it "should enter the next exception's context" do
|
22
54
|
begin
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pry-rescue
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.16'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2013-01-
|
14
|
+
date: 2013-01-21 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: pry
|