hammertime19 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +39 -3
- data/hammertime19.gemspec +2 -2
- data/lib/hammertime19.rb +46 -2
- metadata +2 -2
data/README.rdoc
CHANGED
@@ -7,6 +7,8 @@ hammertime19 is a fork of Avid Grimm's hammertime gem: https://github.com/avdi/h
|
|
7
7
|
hammertime19 is a Ruby 1.9.2+ (MRI and RBX) only version that adds support for starting a pry (https://github.com/pry/pry)
|
8
8
|
session at the exception raise site.
|
9
9
|
|
10
|
+
hammertime19 also adds basic support for intercepting C-level based exceptions.
|
11
|
+
|
10
12
|
== Install
|
11
13
|
|
12
14
|
gem install hammertime19
|
@@ -81,7 +83,7 @@ This enables a fix-and-continue style of development:
|
|
81
83
|
4. Permit by line (don't ask about future errors raised from this point)
|
82
84
|
5. Backtrace (show the call stack leading up to the error)
|
83
85
|
6. Debug (start a debugger)
|
84
|
-
7. Console (start
|
86
|
+
7. Console (start a pry session)
|
85
87
|
What now?
|
86
88
|
2
|
87
89
|
No error raised
|
@@ -90,13 +92,47 @@ This enables a fix-and-continue style of development:
|
|
90
92
|
Attempt (3/3)
|
91
93
|
No error raised
|
92
94
|
|
95
|
+
About non-explicitly raised errors:
|
96
|
+
|
97
|
+
An example of a non-explicitly raised error is if you divide by 0 which creates a
|
98
|
+
ZeroDivisionError.
|
99
|
+
Hammertime19 cannot process these errors in the same way as user raised errors can be processed.
|
100
|
+
However, they can be intercepted, and a pry session can be started at the exception site.
|
101
|
+
|
102
|
+
For example running this code:
|
103
|
+
|
104
|
+
require 'hammertime19'
|
105
|
+
1 / 0
|
106
|
+
|
107
|
+
Gives you a pry console like this:
|
108
|
+
|
109
|
+
=== Stop! Hammertime. ===
|
110
|
+
A C-level error has occurred at h.rb:2:in `/'
|
111
|
+
The error is: <ZeroDivisionError> divided by 0
|
112
|
+
|
113
|
+
From: h.rb @ line 2 :
|
114
|
+
|
115
|
+
1: require 'hammertime19.'
|
116
|
+
=> 2: 1 / 0
|
117
|
+
|
118
|
+
[1] pry(main)>
|
119
|
+
|
120
|
+
These types of errors cannot be recovered from, so when the pry session ends the program exits.
|
121
|
+
|
122
|
+
Hammertime19 doesn't know if the exception will be rescued, so therefore all exceptions that
|
123
|
+
are not explicitly raised will be intercepted in this way.
|
124
|
+
|
125
|
+
If you find that annoying, you can turn of this feature by calling:
|
126
|
+
|
127
|
+
Hammertime.intercept_native = false
|
128
|
+
|
93
129
|
== Known Bugs
|
94
130
|
|
95
|
-
*
|
131
|
+
* Hammertime19 cannot recover from errors that are raised from native code.
|
132
|
+
* Hammertime19 cannot distinguish between native code exceptions that will be rescued and those that won't.
|
96
133
|
|
97
134
|
== TODO
|
98
135
|
|
99
|
-
* Better integration with IRB to enable a "Retry" option.
|
100
136
|
* Tests
|
101
137
|
|
102
138
|
== Dependencies
|
data/hammertime19.gemspec
CHANGED
@@ -2,10 +2,10 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = "hammertime19"
|
5
|
-
s.version = "0.0.
|
5
|
+
s.version = "0.0.5"
|
6
6
|
|
7
7
|
s.authors = ["Kalle Lindstrom"]
|
8
|
-
s.date = "2012-08-
|
8
|
+
s.date = "2012-08-22"
|
9
9
|
s.description = "When this library is required, it replaces the default Ruby exception-raising\nbehavior. When an error is raised, the developer is presented with a menu\nenabling them to ignore the error, view a stack trace, debug the error using IRB\nor ruby-debug, and more.\n"
|
10
10
|
s.email = "lindstrom.kalle@gmail.com"
|
11
11
|
s.extra_rdoc_files = [
|
data/lib/hammertime19.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
#encoding: utf-8
|
2
2
|
|
3
|
-
# https://github.com/kl/
|
3
|
+
# https://github.com/kl/hammertime19
|
4
4
|
# Forked from https://github.com/avdi/hammertime
|
5
5
|
# This fork works only with MRI 1.9.2+ and RBX
|
6
|
-
# Adds support for starting a Pry session at the call site of the exception
|
6
|
+
# Adds support for starting a Pry session at the call site of the exception
|
7
|
+
# and interception (not recovering from) non-raised exceptions.
|
7
8
|
|
8
9
|
require 'thread'
|
9
10
|
require 'highline'
|
@@ -11,6 +12,12 @@ require 'pry'
|
|
11
12
|
require 'binding_of_caller'
|
12
13
|
|
13
14
|
module Hammertime
|
15
|
+
|
16
|
+
class << self
|
17
|
+
attr_accessor :intercept_native
|
18
|
+
end
|
19
|
+
@intercept_native = true
|
20
|
+
|
14
21
|
def self.ignored_errors
|
15
22
|
@ignored_errors ||= [LoadError]
|
16
23
|
end
|
@@ -163,6 +170,43 @@ module Hammertime
|
|
163
170
|
|
164
171
|
end
|
165
172
|
|
173
|
+
#
|
174
|
+
# Modifies the Exception class so that all low level errors
|
175
|
+
# (errors that are not explicitly raised) are intercepted
|
176
|
+
# and a pry session is started at the error source location.
|
177
|
+
# Note it is not (yet?) possible to recover from these
|
178
|
+
# errors. After the pry session is over the program exits.
|
179
|
+
#
|
180
|
+
unless ::Object < Hammertime
|
181
|
+
class Exception
|
182
|
+
|
183
|
+
alias_method :exception_hammertime19_orig, :exception
|
184
|
+
def exception(*args, &block)
|
185
|
+
if ::Hammertime.intercept_native
|
186
|
+
|
187
|
+
# When binding.of_caller(1).pry is called several exceptions
|
188
|
+
# are raised but we only want to start a pry session on the
|
189
|
+
# first (original) exception.
|
190
|
+
# We also don't want to start a pry session if the exception
|
191
|
+
# originates from the hammertime library itself (for example
|
192
|
+
# when hammertime tries to require ruby-debug)
|
193
|
+
unless caller.any? { |t| t.include?("pry/core_extensions.rb") || t.include?("hammertime_raise") }
|
194
|
+
|
195
|
+
puts "\n"
|
196
|
+
puts "=== Stop! Hammertime. ==="
|
197
|
+
puts "A C-level error has occurred at #{caller(2).first}"
|
198
|
+
puts "The error is: <#{self.class}> #{self.message}"
|
199
|
+
|
200
|
+
binding.of_caller(1).pry
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
# Call the original method
|
205
|
+
exception_hammertime19_orig(*args, &block)
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
166
210
|
unless ::Object < Hammertime
|
167
211
|
class ::Object
|
168
212
|
include ::Hammertime
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hammertime19
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-08-
|
12
|
+
date: 2012-08-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: highline
|