pry-capture 0.1 → 1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +5 -90
- data/lib/pry-capture.rb +1 -54
- data/pry-capture.gemspec +7 -7
- metadata +35 -60
- data/LICENSE.MIT +0 -19
- data/Rakefile +0 -16
- data/examples/example.rb +0 -21
- data/examples/example2.rb +0 -20
- data/lib/pry-capture/cli.rb +0 -1
- data/lib/pry-capture/commands.rb +0 -44
- data/lib/pry-capture/core_ext.rb +0 -26
data/README.md
CHANGED
@@ -1,94 +1,9 @@
|
|
1
|
-
pry-capture allows you to start a Pry session on any unhandled exceptions in your code.
|
2
1
|
|
2
|
+
Renamed
|
3
|
+
=======
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
Either `gem install pry-capture`, or add it to the development section of your Gemfile:
|
7
|
-
|
8
|
-
```ruby
|
9
|
-
source :rubygems
|
10
|
-
group :development do
|
11
|
-
gem 'pry-capture'
|
12
|
-
gem 'pry-stack_explorer' # if you're using MRI 1.9 and you want it to be awesome.
|
13
|
-
end
|
14
|
-
```
|
15
|
-
|
16
|
-
Usage
|
17
|
-
=====
|
18
|
-
|
19
|
-
In development, wrap your code in `Pry::capture{ }`; then any exceptions that are raised
|
20
|
-
but not rescued will open a pry session.
|
21
|
-
|
22
|
-
```ruby
|
23
|
-
require 'pry-capture'
|
24
|
-
|
25
|
-
def test
|
26
|
-
raise "foo"
|
27
|
-
rescue => e
|
28
|
-
raise "bar"
|
29
|
-
end
|
30
|
-
|
31
|
-
Pry.capture do
|
32
|
-
test
|
33
|
-
end
|
34
|
-
```
|
35
|
-
|
36
|
-
This will land you in a pry-session:
|
37
|
-
|
38
|
-
```
|
39
|
-
From: examples/example.rb @ line 4 Object#test:
|
40
|
-
|
41
|
-
4: def test
|
42
|
-
5: raise "foo"
|
43
|
-
6: rescue => e
|
44
|
-
=> 7: raise "bar"
|
45
|
-
8: end
|
46
|
-
|
47
|
-
RuntimeError: bar
|
48
|
-
from examples/example.rb:7:in `rescue in test'
|
49
|
-
[1] pry(main)>
|
50
|
-
```
|
51
|
-
|
52
|
-
If you need to find the reason that the exception happened, you can use the `cd-cause`
|
53
|
-
command:
|
54
|
-
|
55
|
-
```
|
56
|
-
[1] pry(main)> cd-cause
|
57
|
-
From: examples/example.rb @ line 4 Object#test:
|
58
|
-
|
59
|
-
4: def test
|
60
|
-
=> 5: raise "foo"
|
61
|
-
6: rescue => e
|
62
|
-
7: raise "bar"
|
63
|
-
8: end
|
64
|
-
|
65
|
-
RuntimeError: foo
|
66
|
-
from examples/example.rb:5:in `test'
|
67
|
-
[1] pry(main)>
|
68
|
-
```
|
69
|
-
|
70
|
-
To get back from `cd-cause` you can either type `<ctrl+d>` or `cd ..`.
|
71
|
-
|
72
|
-
pry-stack explorer
|
73
|
-
==================
|
74
|
-
|
75
|
-
If you're running rubinius, or ruby-1.9, then you can use `pry-capture` alongside
|
76
|
-
`pry-stack_explorer`. This gives you the ability to move `up` or `down` the stack so that
|
77
|
-
you can get a better idea of why your function ended up in a bad state. Run
|
78
|
-
[example2.rb](https://github.com/ConradIrwin/pry-capture/blob/master/examples/example2.rb) to get a feel for what this is like.
|
79
|
-
|
80
|
-
Known bugs
|
81
|
-
==========
|
82
|
-
|
83
|
-
Occasionally, when using ruby-1.8 or jruby, the value for `self` will be incorrect. You
|
84
|
-
will still be able to access local variables, but calling methods will not work as you
|
85
|
-
expect.
|
86
|
-
|
87
|
-
On rbx we are unable to intercept some exceptions thrown from inside the C++ VM, for
|
88
|
-
example the ZeroDivisionError in `1 / 0`.
|
5
|
+
The `pry-capture` gem has been renamed to `pry-rescue` by popular demand. This stub exists
|
6
|
+
so that people already using `pry-capture` can continue doing so without problem.
|
89
7
|
|
90
|
-
|
91
|
-
=======
|
8
|
+
For further information, please look at [pry-rescue on Github](https://github.com/ConradIrwin/pry-rescue).
|
92
9
|
|
93
|
-
Released under the MIT license, see LICENSE.MIT for details. Contributions and bug-reports
|
94
|
-
are welcome.
|
data/lib/pry-capture.rb
CHANGED
@@ -1,54 +1 @@
|
|
1
|
-
require '
|
2
|
-
require 'interception'
|
3
|
-
require 'pry'
|
4
|
-
|
5
|
-
require File.expand_path('../pry-capture/core_ext', __FILE__)
|
6
|
-
require File.expand_path('../pry-capture/commands', __FILE__)
|
7
|
-
|
8
|
-
begin
|
9
|
-
require 'pry-stack_explorer'
|
10
|
-
rescue LoadError
|
11
|
-
end
|
12
|
-
|
13
|
-
class PryCapture
|
14
|
-
class << self
|
15
|
-
|
16
|
-
# Start a Pry session in the context of the exception.
|
17
|
-
# @param [Exception] exception The exception.
|
18
|
-
# @param [Array<Binding>] bindings The call stack.
|
19
|
-
def enter_exception_context(raised)
|
20
|
-
exception, bindings = raised.last
|
21
|
-
|
22
|
-
prune_call_stack!(bindings)
|
23
|
-
|
24
|
-
if defined?(PryStackExplorer)
|
25
|
-
pry :call_stack => bindings, :hooks => pry_hooks(exception, raised)
|
26
|
-
else
|
27
|
-
bindings.first.pry :hooks => pry_hooks(exception, raised)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
private
|
32
|
-
|
33
|
-
# Define the :before_session hook for the Pry instance.
|
34
|
-
# This ensures that the `_ex_` and `_raised_` sticky locals are
|
35
|
-
# properly set.
|
36
|
-
def pry_hooks(ex, raised)
|
37
|
-
hooks = Pry.config.hooks.dup
|
38
|
-
hooks.add_hook(:before_session, :save_captured_exception) do |_, _, _pry_|
|
39
|
-
_pry_.last_exception = ex
|
40
|
-
_pry_.backtrace = ex.backtrace
|
41
|
-
_pry_.sticky_locals.merge!({ :_raised_ => raised })
|
42
|
-
_pry_.exception_handler.call(_pry_.output, ex, _pry_)
|
43
|
-
end
|
44
|
-
|
45
|
-
hooks
|
46
|
-
end
|
47
|
-
|
48
|
-
# Sanitize the call stack.
|
49
|
-
# @param [Array<Binding>] bindings The call stack.
|
50
|
-
def prune_call_stack!(bindings)
|
51
|
-
bindings.delete_if { |b| [Pry, Interception].include?(b.eval("self")) }
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
1
|
+
require 'pry-rescue'
|
data/pry-capture.gemspec
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'pry-capture'
|
3
|
-
s.version = '0
|
3
|
+
s.version = '1.0'
|
4
4
|
s.summary = 'Open a pry session on any unhandled exceptions'
|
5
|
-
s.description = '
|
6
|
-
s.homepage = 'https://github.com/ConradIrwin/pry-
|
7
|
-
s.email = ['conrad.irwin@gmail.com'
|
8
|
-
s.authors = ['Conrad Irwin'
|
5
|
+
s.description = 'This gem just installs pry-rescue. Please prefer that gem.'
|
6
|
+
s.homepage = 'https://github.com/ConradIrwin/pry-rescue'
|
7
|
+
s.email = ['conrad.irwin@gmail.com']
|
8
|
+
s.authors = ['Conrad Irwin']
|
9
9
|
s.files = `git ls-files`.split("\n")
|
10
|
-
s.require_paths = [
|
10
|
+
s.require_paths = ['lib']
|
11
11
|
|
12
|
-
s.add_dependency '
|
12
|
+
s.add_dependency 'pry-rescue'
|
13
13
|
end
|
metadata
CHANGED
@@ -1,90 +1,65 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: pry-capture
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '1.0'
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 1
|
9
|
-
version: "0.1"
|
10
6
|
platform: ruby
|
11
|
-
authors:
|
7
|
+
authors:
|
12
8
|
- Conrad Irwin
|
13
|
-
- banisterfiend
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
prerelease: false
|
23
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
12
|
+
date: 2012-08-15 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: pry-rescue
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
24
17
|
none: false
|
25
|
-
requirements:
|
26
|
-
- -
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
|
29
|
-
segments:
|
30
|
-
- 0
|
31
|
-
version: "0"
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
32
22
|
type: :runtime
|
33
|
-
|
34
|
-
|
35
|
-
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
description: This gem just installs pry-rescue. Please prefer that gem.
|
31
|
+
email:
|
36
32
|
- conrad.irwin@gmail.com
|
37
|
-
- jrmair@gmail.com
|
38
33
|
executables: []
|
39
|
-
|
40
34
|
extensions: []
|
41
|
-
|
42
35
|
extra_rdoc_files: []
|
43
|
-
|
44
|
-
files:
|
45
|
-
- LICENSE.MIT
|
36
|
+
files:
|
46
37
|
- README.md
|
47
|
-
- Rakefile
|
48
|
-
- examples/example.rb
|
49
|
-
- examples/example2.rb
|
50
38
|
- lib/pry-capture.rb
|
51
|
-
- lib/pry-capture/cli.rb
|
52
|
-
- lib/pry-capture/commands.rb
|
53
|
-
- lib/pry-capture/core_ext.rb
|
54
39
|
- pry-capture.gemspec
|
55
|
-
homepage: https://github.com/ConradIrwin/pry-
|
40
|
+
homepage: https://github.com/ConradIrwin/pry-rescue
|
56
41
|
licenses: []
|
57
|
-
|
58
42
|
post_install_message:
|
59
43
|
rdoc_options: []
|
60
|
-
|
61
|
-
require_paths:
|
44
|
+
require_paths:
|
62
45
|
- lib
|
63
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
47
|
none: false
|
65
|
-
requirements:
|
66
|
-
- -
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
|
69
|
-
|
70
|
-
- 0
|
71
|
-
version: "0"
|
72
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ! '>='
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
53
|
none: false
|
74
|
-
requirements:
|
75
|
-
- -
|
76
|
-
- !ruby/object:Gem::Version
|
77
|
-
|
78
|
-
segments:
|
79
|
-
- 0
|
80
|
-
version: "0"
|
54
|
+
requirements:
|
55
|
+
- - ! '>='
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
81
58
|
requirements: []
|
82
|
-
|
83
59
|
rubyforge_project:
|
84
60
|
rubygems_version: 1.8.24
|
85
61
|
signing_key:
|
86
62
|
specification_version: 3
|
87
63
|
summary: Open a pry session on any unhandled exceptions
|
88
64
|
test_files: []
|
89
|
-
|
90
65
|
has_rdoc:
|
data/LICENSE.MIT
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
Copyright (c) 2012 Conrad Irwin <conrad.irwin@gmail.com>
|
2
|
-
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
-
of this software and associated documentation files (the "Software"), to deal
|
5
|
-
in the Software without restriction, including without limitation the rights
|
6
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
-
copies of the Software, and to permit persons to whom the Software is
|
8
|
-
furnished to do so, subject to the following conditions:
|
9
|
-
|
10
|
-
The above copyright notice and this permission notice shall be included in
|
11
|
-
all copies or substantial portions of the Software.
|
12
|
-
|
13
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
-
THE SOFTWARE.
|
data/Rakefile
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
desc "Run example"
|
2
|
-
task :example do
|
3
|
-
sh "ruby -I./lib/ ./examples/example.rb "
|
4
|
-
end
|
5
|
-
|
6
|
-
desc "Run example 2"
|
7
|
-
task :example2 do
|
8
|
-
sh "ruby -I./lib/ ./examples/example2.rb "
|
9
|
-
end
|
10
|
-
|
11
|
-
desc "Run tests"
|
12
|
-
task :test do
|
13
|
-
sh 'rspec spec -r ./spec/spec_helpers.rb'
|
14
|
-
end
|
15
|
-
|
16
|
-
|
data/examples/example.rb
DELETED
data/examples/example2.rb
DELETED
data/lib/pry-capture/cli.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require 'pry-capture'
|
data/lib/pry-capture/commands.rb
DELETED
@@ -1,44 +0,0 @@
|
|
1
|
-
Pry::Commands.create_command "cd-cause", "Move to the previously raised exception" do
|
2
|
-
|
3
|
-
banner <<-BANNER
|
4
|
-
Usage: cd-cause
|
5
|
-
|
6
|
-
Starts a new pry session at the previously raised exception.
|
7
|
-
|
8
|
-
This is useful if you've caught one exception, and raised another,
|
9
|
-
if you need to find out why the original was raised.
|
10
|
-
|
11
|
-
@example
|
12
|
-
5. def foo
|
13
|
-
6. raise "one"
|
14
|
-
7. rescue
|
15
|
-
8. => raise "two"
|
16
|
-
9. end
|
17
|
-
|
18
|
-
pry> cd-cause
|
19
|
-
|
20
|
-
5. def foo
|
21
|
-
6. => raise "one"
|
22
|
-
7. rescue
|
23
|
-
8. raise "two"
|
24
|
-
9. end
|
25
|
-
|
26
|
-
Once you have finished with the internal exception type <ctrl+d> or cd .. to
|
27
|
-
return to where you were.
|
28
|
-
|
29
|
-
If you have many layers of exceptions that are rescued and then re-raised, you
|
30
|
-
can repeat cd-cause as many times as you need.
|
31
|
-
BANNER
|
32
|
-
|
33
|
-
def process
|
34
|
-
raised = target.eval("_raised_ rescue nil")
|
35
|
-
raise Pry::CommandError, "cd-cause only works in a pry session created by Pry::capture{}" unless raised
|
36
|
-
raised.pop
|
37
|
-
|
38
|
-
if raised.any?
|
39
|
-
PryCapture.enter_exception_context(raised)
|
40
|
-
else
|
41
|
-
raise Pry::CommandError, "No previous exception detected"
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
data/lib/pry-capture/core_ext.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
class Pry
|
2
|
-
|
3
|
-
# Start a pry session on any unhandled exceptions within this block.
|
4
|
-
#
|
5
|
-
# @example
|
6
|
-
# Pry::capture do
|
7
|
-
# raise "foo"
|
8
|
-
# end
|
9
|
-
#
|
10
|
-
# @return [Object] The return value of the block
|
11
|
-
def self.capture(&block)
|
12
|
-
raised = []
|
13
|
-
|
14
|
-
Interception.listen(block) do |exception, binding|
|
15
|
-
if defined?(PryStackExplorer)
|
16
|
-
raised << [exception, binding.callers]
|
17
|
-
else
|
18
|
-
raised << [exception, Array(binding)]
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
rescue Exception => e
|
23
|
-
PryCapture.enter_exception_context(raised)
|
24
|
-
raise
|
25
|
-
end
|
26
|
-
end
|