praise 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +7 -0
- data/README_FULL.md +79 -0
- data/lib/praise.rb +1 -1
- metadata +5 -1
data/README.md
ADDED
data/README_FULL.md
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
# Praise
|
2
|
+
|
3
|
+
Pry + raise = praise. A small gem for intercepting raise calls to dig up hidden and buried exceptions.
|
4
|
+
|
5
|
+
- Documentation: {http://blog.pitr.ch/praise}
|
6
|
+
- Source: {https://github.com/pitr-ch/praise}
|
7
|
+
- Blog: {http://blog.pitr.ch}
|
8
|
+
|
9
|
+
## Difference between `prise` and `pry-rescue`
|
10
|
+
|
11
|
+
Praise allows a developer to investigate all exceptions including the ones rescued later.
|
12
|
+
`pry-rescue` on the other hand will work only for exceptions which are un-handled by the process.
|
13
|
+
Typical use-case is e.g. a worker, which is rescuing all exceptions. `pry-rescue` cannot help with
|
14
|
+
investigation of these exceptions.
|
15
|
+
|
16
|
+
## Install
|
17
|
+
|
18
|
+
1. require the gem early, e.g. in `contig/application.rb` in rails
|
19
|
+
2. install `Praise`, e.g.
|
20
|
+
|
21
|
+
Praise = PraiseImpl.
|
22
|
+
new(File.join(root, Katello.early_config.praise.ignored_path),
|
23
|
+
-> level, message { Logging.logger['praise'].add Logging.level_num(level), message })
|
24
|
+
|
25
|
+
And that's it.
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
Whenever an exception is risen and exception is not ignored then you will be dropped to a Pry session.
|
30
|
+
|
31
|
+
From: /Users/pitr/Workspace/personal/praise/lib/praise.rb @ line 75 Kernel#raise:
|
32
|
+
|
33
|
+
64: define_method :raise do |*args|
|
34
|
+
65: begin
|
35
|
+
66: message = args.find { |o| o.kind_of? String }
|
36
|
+
67: backtrace = args.find { |o| o.kind_of? Array }
|
37
|
+
68: exception_generator = args.find { |o| ![message, backtrace].include? o } || RuntimeError
|
38
|
+
69: exception = message ? exception_generator.exception(message) : exception_generator.exception
|
39
|
+
70: message ||= exception.message
|
40
|
+
71: risen_at = caller(1).first
|
41
|
+
72:
|
42
|
+
73: unless Thread.current[:__pry_in_rescue__] || praise.ignore?(exception, message, risen_at)
|
43
|
+
74: Thread.current[:__pry_in_rescue__] = true
|
44
|
+
=> 75: binding.pry
|
45
|
+
76: end
|
46
|
+
77:
|
47
|
+
78: _original_raise *args
|
48
|
+
79: ensure
|
49
|
+
80: Thread.current[:__pry_in_rescue__] = false
|
50
|
+
81: end
|
51
|
+
82: end
|
52
|
+
|
53
|
+
[1] pry(#<Delayed::Backend::ActiveRecord::Job>)>
|
54
|
+
|
55
|
+
Stack can be explored with pry-stack_explorer plugin for Pry:
|
56
|
+
|
57
|
+
pry-stack_explorer (v0.4.9)
|
58
|
+
down Go down to the callee's context.
|
59
|
+
frame Switch to a particular frame.
|
60
|
+
show-stack Show all frames
|
61
|
+
up Go up to the caller's context.
|
62
|
+
|
63
|
+
Use `up` or `frame 1` to get to the binding and line where the exception was risen.
|
64
|
+
When you hit `C-d` exception is risen as usual.
|
65
|
+
|
66
|
+
## Ignoring
|
67
|
+
|
68
|
+
If there were no method to ignore some exceptions, It would drop to pry for every single `#raise` call, which
|
69
|
+
would not be very useful. Therefore there is a yml file where filters can be specified to ignore exceptions.
|
70
|
+
It can be updated at runtime {PraiseImpl#add_rule}.
|
71
|
+
|
72
|
+
### Ignore file structure
|
73
|
+
|
74
|
+
[{ class: 'AClass' }, # exception ignored when exception.class.to_s == 'AClass'
|
75
|
+
{ message: /missing plugin/ }, # exception ignored when exception.message =~ /missing plugin/
|
76
|
+
{ line: /rubygems/ }, # exception ignored when risen_at =~ /rubygems/
|
77
|
+
{ class: RuntimeError, message: /nothing/ }
|
78
|
+
# exception ignored when both rules are met
|
79
|
+
].to_yaml
|
data/lib/praise.rb
CHANGED
@@ -20,7 +20,7 @@ class PraiseImpl
|
|
20
20
|
install
|
21
21
|
end
|
22
22
|
|
23
|
-
# @return [Array<Hash{:class, :message, :line => Regexp, String}] rules for exception ignoring
|
23
|
+
# @return [Array<Hash{:class, :message, :line => Regexp, String}>] rules for exception ignoring
|
24
24
|
def ignored
|
25
25
|
@ignored ||= YAML.load File.read(@ignored_path)
|
26
26
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: praise
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -114,9 +114,13 @@ executables: []
|
|
114
114
|
extensions: []
|
115
115
|
extra_rdoc_files:
|
116
116
|
- MIT-LICENSE
|
117
|
+
- README.md
|
118
|
+
- README_FULL.md
|
117
119
|
files:
|
118
120
|
- lib/praise.rb
|
119
121
|
- MIT-LICENSE
|
122
|
+
- README.md
|
123
|
+
- README_FULL.md
|
120
124
|
- spec/praise.rb
|
121
125
|
homepage: https://github.com/pitr-ch/praise
|
122
126
|
licenses:
|