coaster 1.0.3 → 1.0.8
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/core_ext/standard_error.rb +61 -46
- data/lib/coaster/core_ext/standard_error/raven.rb +1 -1
- data/lib/coaster/version.rb +1 -1
- data/test/test_helper.rb +5 -0
- data/test/test_standard_error.rb +23 -0
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 30a1cd3050a41f9d174b8f163bc73c86519e46535c875664e044d09b5bf5f1a6
|
4
|
+
data.tar.gz: 309a1fd5431ced086709b694f9f7a95f330f5342dc09841729f491ab6f8276ca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9d93263418966554adf4ec4f509a2cd77f8ab3f478d1aeaa9188e1b36856e1ba5dad2ae8e988bbfb28a5324b790da7dc23e429e6f1e0df1f369d0008414dc45d
|
7
|
+
data.tar.gz: be7411b223a6db84e0e53d738010ad4a620f73b9e2424cb0bfa3c5b9ab5a47bf0d16797c419aa5fd393bc291a67a6946db29f7b783cd79a0230ff3a88a4fdd37
|
@@ -4,19 +4,34 @@ class StandardError
|
|
4
4
|
cattr_accessor :cleaner, :cause_cleaner
|
5
5
|
|
6
6
|
class << self
|
7
|
-
def status
|
8
|
-
999999 # Unknown
|
9
|
-
end
|
7
|
+
def status; 999999 end # Unknown
|
10
8
|
alias_method :code, :status
|
11
|
-
|
12
|
-
def
|
13
|
-
|
14
|
-
end
|
9
|
+
def http_status; 500 end
|
10
|
+
def report?; true end
|
11
|
+
def intentional?; false end
|
15
12
|
|
16
13
|
def title
|
17
14
|
t = _translate('.title')
|
18
15
|
t.instance_variable_defined?(:@missing) ? nil : t
|
19
16
|
end
|
17
|
+
|
18
|
+
def before_logging(name, &block)
|
19
|
+
@before_logging_blocks ||= {}
|
20
|
+
@before_logging_blocks[name] = block
|
21
|
+
end
|
22
|
+
def before_logging_blocks
|
23
|
+
@before_logging_blocks ||= {}
|
24
|
+
superclass <= StandardError ? superclass.before_logging_blocks.merge(@before_logging_blocks) : @before_logging_blocks
|
25
|
+
end
|
26
|
+
|
27
|
+
def after_logging(name, &block)
|
28
|
+
@after_logging_blocks ||= {}
|
29
|
+
@after_logging_blocks[name] = block
|
30
|
+
end
|
31
|
+
def after_logging_blocks
|
32
|
+
@after_logging_blocks ||= {}
|
33
|
+
superclass <= StandardError ? superclass.after_logging_blocks.merge(@after_logging_blocks) : @after_logging_blocks
|
34
|
+
end
|
20
35
|
end
|
21
36
|
|
22
37
|
attr_accessor :tags, :level, :tkey, :fingerprint
|
@@ -66,17 +81,11 @@ class StandardError
|
|
66
81
|
super(msg)
|
67
82
|
end
|
68
83
|
|
69
|
-
def safe_message
|
70
|
-
|
71
|
-
end
|
72
|
-
|
73
|
-
def
|
74
|
-
self.class.status
|
75
|
-
end
|
76
|
-
|
77
|
-
def title
|
78
|
-
attributes[:title] || self.class.title
|
79
|
-
end
|
84
|
+
def safe_message; message || '' end
|
85
|
+
def status; self.class.status end
|
86
|
+
def before_logging_blocks; self.class.before_logging_blocks end
|
87
|
+
def after_logging_blocks; self.class.after_logging_blocks end
|
88
|
+
def root_cause; cause.respond_to?(:root_cause) ? cause.root_cause : self end
|
80
89
|
|
81
90
|
def attributes
|
82
91
|
return @attributes if defined?(@attributes)
|
@@ -88,21 +97,25 @@ class StandardError
|
|
88
97
|
end
|
89
98
|
alias_method :attr, :attributes
|
90
99
|
|
91
|
-
def http_status
|
92
|
-
|
93
|
-
end
|
94
|
-
|
95
|
-
def
|
96
|
-
|
97
|
-
end
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
def
|
104
|
-
attributes[:
|
105
|
-
|
100
|
+
def http_status; attributes[:http_status] || self.class.http_status end
|
101
|
+
def http_status=(value); attributes[:http_status] = value end
|
102
|
+
def code; attributes[:code] || status end
|
103
|
+
def code=(value); attributes[:code] = value end
|
104
|
+
def title; attributes[:title] || self.class.title end
|
105
|
+
def it_might_happen?; attributes[:it] == :might_happen end
|
106
|
+
def it_should_not_happen?; attributes[:it] == :should_not_happen end
|
107
|
+
def report?
|
108
|
+
return attributes[:report] if attributes.key?(:report)
|
109
|
+
return false if it_might_happen?
|
110
|
+
self.class.report?
|
111
|
+
end
|
112
|
+
def intentional? # not logging in test
|
113
|
+
return attributes[:intentional] if attributes.key?(:intentional)
|
114
|
+
return true if it_should_not_happen?
|
115
|
+
self.class.intentional?
|
116
|
+
end
|
117
|
+
def object; attributes[:object] || attributes[:obj] end
|
118
|
+
alias_method :obj, :object
|
106
119
|
|
107
120
|
# description is user friendly messages, do not use error's message
|
108
121
|
# error message is not user friendly in many cases.
|
@@ -122,15 +135,6 @@ class StandardError
|
|
122
135
|
attributes[:descriptions]
|
123
136
|
end
|
124
137
|
|
125
|
-
def object
|
126
|
-
attributes[:object] || attributes[:obj]
|
127
|
-
end
|
128
|
-
alias_method :obj, :object
|
129
|
-
|
130
|
-
def root_cause
|
131
|
-
cause.respond_to?(:root_cause) ? cause.root_cause : self
|
132
|
-
end
|
133
|
-
|
134
138
|
def to_hash
|
135
139
|
hash = attributes.merge(
|
136
140
|
type: self.class.name, status: status,
|
@@ -198,16 +202,24 @@ class StandardError
|
|
198
202
|
end
|
199
203
|
|
200
204
|
def logging(options = {})
|
201
|
-
|
202
|
-
|
203
|
-
|
205
|
+
before_logging_blocks.values.each { |blk| instance_exec &blk }
|
206
|
+
|
207
|
+
logger = nil
|
208
|
+
if defined?(Rails)
|
209
|
+
return if Rails.env.test? && (intentional? || !report?)
|
210
|
+
logger = Rails.logger
|
211
|
+
end
|
212
|
+
logger = options[:logger] || Coaster.logger || logger
|
213
|
+
return unless logger
|
204
214
|
|
205
215
|
cl = options[:cleaner] || cleaner
|
206
216
|
msg = to_detail
|
207
217
|
|
208
218
|
if cl && backtrace
|
219
|
+
bt = cl.clean(backtrace)
|
220
|
+
bt = bt[0..2] if intentional?
|
209
221
|
msg += "\tBACKTRACE:\n\t"
|
210
|
-
msg +=
|
222
|
+
msg += bt.join("\n\t")
|
211
223
|
end
|
212
224
|
|
213
225
|
if level && logger.respond_to?(level)
|
@@ -215,5 +227,8 @@ class StandardError
|
|
215
227
|
else
|
216
228
|
logger.error(msg)
|
217
229
|
end
|
230
|
+
msg
|
231
|
+
ensure
|
232
|
+
after_logging_blocks.values.each { |blk| instance_exec &blk }
|
218
233
|
end
|
219
234
|
end
|
@@ -38,7 +38,7 @@ class StandardError
|
|
38
38
|
|
39
39
|
def capture(options = {})
|
40
40
|
return if options.key?(:report) && !options[:report]
|
41
|
-
return
|
41
|
+
return unless report?
|
42
42
|
nt = notes(options)
|
43
43
|
Raven.capture_exception(self, level: nt[:level]) do |event|
|
44
44
|
event.user.merge!(nt[:user] || {})
|
data/lib/coaster/version.rb
CHANGED
data/test/test_helper.rb
CHANGED
data/test/test_standard_error.rb
CHANGED
@@ -155,5 +155,28 @@ LOG
|
|
155
155
|
e.descriptions.merge!(a: 1)
|
156
156
|
assert_equal e.descriptions['a'], 1
|
157
157
|
end
|
158
|
+
|
159
|
+
class SampleErrorSub < SampleError; end
|
160
|
+
class SampleErrorSubSub < SampleErrorSub
|
161
|
+
def it_might_happen?; true end
|
162
|
+
end
|
163
|
+
SampleError.after_logging(:blah) do
|
164
|
+
self.attributes[:abc] = 100
|
165
|
+
@blah = 101
|
166
|
+
end
|
167
|
+
def test_before_logging
|
168
|
+
e = SampleErrorSubSub.new(m: 'foo')
|
169
|
+
assert !e.after_logging_blocks[:blah].nil?
|
170
|
+
e.logging
|
171
|
+
assert_equal e.attributes[:abc], 100
|
172
|
+
assert_equal e.instance_variable_get(:@blah), 101
|
173
|
+
end
|
174
|
+
class SampleErrorMightHappen < SampleErrorSub
|
175
|
+
def it_might_happen?; true end
|
176
|
+
end
|
177
|
+
def test_might_happen
|
178
|
+
e = SampleErrorMightHappen.new('fbar')
|
179
|
+
assert !e.report?
|
180
|
+
end
|
158
181
|
end
|
159
182
|
end
|
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: 1.0.
|
4
|
+
version: 1.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- buzz jung
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-09-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: i18n
|
@@ -226,7 +226,7 @@ signing_key:
|
|
226
226
|
specification_version: 4
|
227
227
|
summary: A little convenient feature for standard library
|
228
228
|
test_files:
|
229
|
-
- test/test_helper.rb
|
230
|
-
- test/test_standard_error.rb
|
231
|
-
- test/locales/en.yml
|
232
229
|
- test/test_object_translation.rb
|
230
|
+
- test/locales/en.yml
|
231
|
+
- test/test_standard_error.rb
|
232
|
+
- test/test_helper.rb
|