coaster 0.3.4 → 0.3.5
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.
- checksums.yaml +4 -4
- data/lib/coaster/backtrace_cleaner.rb +78 -0
- data/lib/coaster/core_ext/standard_error.rb +17 -11
- data/lib/coaster/version.rb +1 -1
- data/lib/coaster.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cf1f98ccd896c61cd25584533b7895e027599525
|
4
|
+
data.tar.gz: f2ce5af045ad7c1c75511cb01b96c5b0153ab800
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2af452b0fcd5316cd5da74cbcbaf37cd46a5ee4cd32e938dc5f910aa89a7bcdbaa017a0245a2dbb5d56a5348cfeecf95e35c28d96fcdc0a0e532c336ef1cba92
|
7
|
+
data.tar.gz: 0b5b7d294968de6501437e3763fff5301caae53b18d45cfc916956e60b5720590ff388681abc06131659014a189afa2bccbcb811162bd610c98a1e65399a63e4
|
@@ -0,0 +1,78 @@
|
|
1
|
+
class Coaster::BacktraceCleaner
|
2
|
+
attr_accessor :least
|
3
|
+
|
4
|
+
def initialize
|
5
|
+
@filters, @silencers = [], []
|
6
|
+
@least = 10
|
7
|
+
end
|
8
|
+
|
9
|
+
# Returns the backtrace after all filters and silencers have been run
|
10
|
+
# against it. Filters run first, then silencers.
|
11
|
+
def clean(backtrace, kind = :silent)
|
12
|
+
filtered = filter_backtrace(backtrace)
|
13
|
+
|
14
|
+
case kind
|
15
|
+
when :silent
|
16
|
+
silence(filtered)
|
17
|
+
when :noise
|
18
|
+
noise(filtered)
|
19
|
+
else
|
20
|
+
filtered
|
21
|
+
end
|
22
|
+
end
|
23
|
+
alias :filter :clean
|
24
|
+
|
25
|
+
# Adds a filter from the block provided. Each line in the backtrace will be
|
26
|
+
# mapped against this filter.
|
27
|
+
#
|
28
|
+
# # Will turn "/my/rails/root/app/models/person.rb" into "/app/models/person.rb"
|
29
|
+
# backtrace_cleaner.add_filter { |line| line.gsub(Rails.root, '') }
|
30
|
+
def add_filter(&block)
|
31
|
+
@filters << block
|
32
|
+
end
|
33
|
+
|
34
|
+
# Adds a silencer from the block provided. If the silencer returns +true+
|
35
|
+
# for a given line, it will be excluded from the clean backtrace.
|
36
|
+
#
|
37
|
+
# # Will reject all lines that include the word "mongrel", like "/gems/mongrel/server.rb" or "/app/my_mongrel_server/rb"
|
38
|
+
# backtrace_cleaner.add_silencer { |line| line =~ /mongrel/ }
|
39
|
+
def add_silencer(&block)
|
40
|
+
@silencers << block
|
41
|
+
end
|
42
|
+
|
43
|
+
# Removes all silencers, but leaves in the filters. Useful if your
|
44
|
+
# context of debugging suddenly expands as you suspect a bug in one of
|
45
|
+
# the libraries you use.
|
46
|
+
def remove_silencers!
|
47
|
+
@silencers = []
|
48
|
+
end
|
49
|
+
|
50
|
+
# Removes all filters, but leaves in the silencers. Useful if you suddenly
|
51
|
+
# need to see entire filepaths in the backtrace that you had already
|
52
|
+
# filtered out.
|
53
|
+
def remove_filters!
|
54
|
+
@filters = []
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
def filter_backtrace(backtrace)
|
59
|
+
@filters.each do |f|
|
60
|
+
backtrace = backtrace.map { |line| f.call(line) }
|
61
|
+
end
|
62
|
+
|
63
|
+
backtrace
|
64
|
+
end
|
65
|
+
|
66
|
+
def silence(backtrace)
|
67
|
+
least_bt = backtrace.shift(least)
|
68
|
+
@silencers.each do |s|
|
69
|
+
backtrace = backtrace.reject { |line| s.call(line) }
|
70
|
+
end
|
71
|
+
|
72
|
+
least_bt + backtrace
|
73
|
+
end
|
74
|
+
|
75
|
+
def noise(backtrace)
|
76
|
+
backtrace - silence(backtrace)
|
77
|
+
end
|
78
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'coaster/core_ext/object_translation'
|
2
2
|
|
3
3
|
class StandardError
|
4
|
-
cattr_accessor :cleaner
|
4
|
+
cattr_accessor :cleaner, :cause_cleaner
|
5
5
|
|
6
6
|
class << self
|
7
7
|
def status
|
@@ -51,20 +51,23 @@ class StandardError
|
|
51
51
|
@tkey = hash.delete(:tkey)
|
52
52
|
msg = cause.message if msg.nil? && cause
|
53
53
|
@attributes.merge!(hash)
|
54
|
-
when String
|
54
|
+
when String then
|
55
55
|
msg = message
|
56
|
-
when FalseClass then
|
57
|
-
msg =
|
56
|
+
when FalseClass, NilClass then
|
57
|
+
msg = ''
|
58
58
|
else
|
59
|
-
msg = message
|
59
|
+
msg = message.class.name
|
60
60
|
@attributes[:object] = message
|
61
61
|
end
|
62
62
|
|
63
63
|
@fingerprint = [] unless @fingerprint.is_a?(Array)
|
64
64
|
@tags = {} unless @tags.is_a?(Hash)
|
65
|
-
msg
|
65
|
+
msg ||= ''
|
66
66
|
super(msg)
|
67
|
-
|
67
|
+
end
|
68
|
+
|
69
|
+
def safe_message
|
70
|
+
message || ''
|
68
71
|
end
|
69
72
|
|
70
73
|
def status
|
@@ -98,7 +101,7 @@ class StandardError
|
|
98
101
|
def description
|
99
102
|
dsc = attributes[:description] || attributes[:desc]
|
100
103
|
return dsc if dsc
|
101
|
-
msg =
|
104
|
+
msg = safe_message.dup
|
102
105
|
msg.instance_variable_set(:@raw, true)
|
103
106
|
msg
|
104
107
|
end
|
@@ -141,7 +144,7 @@ class StandardError
|
|
141
144
|
|
142
145
|
def to_detail
|
143
146
|
lg = "[#{self.class.name}] status:#{status}"
|
144
|
-
lg += "\n\tMESSAGE: #{
|
147
|
+
lg += "\n\tMESSAGE: #{safe_message.gsub(/\n/, "\n\t\t")}"
|
145
148
|
instance_variables.each do |var|
|
146
149
|
if var.to_s.start_with?('@_')
|
147
150
|
next
|
@@ -160,6 +163,9 @@ class StandardError
|
|
160
163
|
else
|
161
164
|
lg += "\n\tCAUSE: #{cause.class.name}: #{cause.message.gsub(/\n/, "\n\t\t")}"
|
162
165
|
end
|
166
|
+
if cause_cleaner && cause.backtrace
|
167
|
+
lg += cause_cleaner.clean(cause.backtrace).join("\n\t\t")
|
168
|
+
end
|
163
169
|
end
|
164
170
|
lg << "\n"
|
165
171
|
end
|
@@ -185,8 +191,8 @@ class StandardError
|
|
185
191
|
msg = to_detail
|
186
192
|
|
187
193
|
if cl && backtrace
|
188
|
-
msg += "\
|
189
|
-
msg +=
|
194
|
+
msg += "\tBACKTRACE:\n\t"
|
195
|
+
msg += cl.clean(backtrace).join("\n\t")
|
190
196
|
end
|
191
197
|
|
192
198
|
logger.tagged(*rails_tag) do
|
data/lib/coaster/version.rb
CHANGED
data/lib/coaster.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: coaster
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- buzz jung
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-11-
|
11
|
+
date: 2016-11-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: i18n
|
@@ -186,6 +186,7 @@ files:
|
|
186
186
|
- README.md
|
187
187
|
- Rakefile
|
188
188
|
- lib/coaster.rb
|
189
|
+
- lib/coaster/backtrace_cleaner.rb
|
189
190
|
- lib/coaster/core_ext.rb
|
190
191
|
- lib/coaster/core_ext/object_translation.rb
|
191
192
|
- lib/coaster/core_ext/standard_error.rb
|