coaster 1.0.2 → 1.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/coaster/core_ext/object_translation.rb +1 -1
- data/lib/coaster/core_ext/standard_error.rb +66 -44
- 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 +28 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ca45b5184489708bdeeb0381f2d540576f1b58cc324b3dca4f5bd698f021c687
|
4
|
+
data.tar.gz: 69ab2837c8159634389fefc993503c130bb8e14efcda3a2621646d909a3f9a4f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 417805608b285316128c95f4aadaa83d26ab9f2666e0273e1ee987baca5b4d346596dd0d1d8de925f7273bf6a4ee3ac057ceaf43c6213874b025e9df51533c5f
|
7
|
+
data.tar.gz: 795b2a27aaadf52aad1e6f723397dc13be68e3cd7028ca5c1a982cd9dda6cbe92d688ea4324ed72fd609274993c91c29978bf0d2ecc52bad7b4d6a82c68b4341
|
@@ -39,13 +39,13 @@ class Object
|
|
39
39
|
end
|
40
40
|
|
41
41
|
if result.is_a?(I18n::MissingTranslation)
|
42
|
-
Coaster.logger && Coaster.logger.warn(result)
|
43
42
|
unless options.key?(:original_missing)
|
44
43
|
options.merge!(original_missing: result)
|
45
44
|
end
|
46
45
|
|
47
46
|
if key_class.superclass == Object || key_class == Object
|
48
47
|
return options[:description] if options[:description].present?
|
48
|
+
Coaster.logger && Coaster.logger.warn(result)
|
49
49
|
throw :exception, result if options[:original_throw]
|
50
50
|
missing = options[:original_missing] || result
|
51
51
|
msg = missing.message
|
@@ -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.after_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.
|
@@ -115,13 +128,11 @@ class StandardError
|
|
115
128
|
end
|
116
129
|
alias_method :desc, :description
|
117
130
|
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
def root_cause
|
124
|
-
cause.respond_to?(:root_cause) ? cause.root_cause : self
|
131
|
+
# more user friendly messages
|
132
|
+
def descriptions
|
133
|
+
return attributes[:descriptions] if attributes[:descriptions]
|
134
|
+
attributes[:descriptions] = {}
|
135
|
+
attributes[:descriptions]
|
125
136
|
end
|
126
137
|
|
127
138
|
def to_hash
|
@@ -191,16 +202,25 @@ class StandardError
|
|
191
202
|
end
|
192
203
|
|
193
204
|
def logging(options = {})
|
194
|
-
|
195
|
-
|
196
|
-
return
|
205
|
+
before_logging_blocks.values.each { |blk| instance_exec &blk }
|
206
|
+
|
207
|
+
return unless report?
|
208
|
+
logger = nil
|
209
|
+
if defined?(Rails)
|
210
|
+
return if Rails.env.test? && intentional?
|
211
|
+
logger = Rails.logger
|
212
|
+
end
|
213
|
+
logger = options[:logger] || Coaster.logger || logger
|
214
|
+
return unless logger
|
197
215
|
|
198
216
|
cl = options[:cleaner] || cleaner
|
199
217
|
msg = to_detail
|
200
218
|
|
201
219
|
if cl && backtrace
|
220
|
+
bt = cl.clean(backtrace)
|
221
|
+
bt = bt[0..2] if intentional?
|
202
222
|
msg += "\tBACKTRACE:\n\t"
|
203
|
-
msg +=
|
223
|
+
msg += bt.join("\n\t")
|
204
224
|
end
|
205
225
|
|
206
226
|
if level && logger.respond_to?(level)
|
@@ -208,5 +228,7 @@ class StandardError
|
|
208
228
|
else
|
209
229
|
logger.error(msg)
|
210
230
|
end
|
231
|
+
|
232
|
+
after_logging_blocks.values.each { |blk| instance_exec &blk }
|
211
233
|
end
|
212
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
@@ -148,5 +148,33 @@ LOG
|
|
148
148
|
assert_equal e.to_hash['http_status'], 500
|
149
149
|
assert e.to_hash['message'] =~ /undefined local variable or method `aa'/
|
150
150
|
end
|
151
|
+
|
152
|
+
def test_descriptions
|
153
|
+
raise SampleError
|
154
|
+
rescue => e
|
155
|
+
e.descriptions.merge!(a: 1)
|
156
|
+
assert_equal e.descriptions['a'], 1
|
157
|
+
end
|
158
|
+
|
159
|
+
class SampleErrorSub < SampleError; end
|
160
|
+
class SampleErrorSubSub < SampleErrorSub; end
|
161
|
+
SampleError.after_logging(:blah) do
|
162
|
+
self.attributes[:abc] = 100
|
163
|
+
@blah = 101
|
164
|
+
end
|
165
|
+
def test_before_logging
|
166
|
+
e = SampleErrorSubSub.new(m: 'foo')
|
167
|
+
assert !e.after_logging_blocks[:blah].nil?
|
168
|
+
e.logging
|
169
|
+
assert_equal e.attributes[:abc], 100
|
170
|
+
assert_equal e.instance_variable_get(:@blah), 101
|
171
|
+
end
|
172
|
+
class SampleErrorMightHappen < SampleErrorSub
|
173
|
+
def it_might_happen?; true end
|
174
|
+
end
|
175
|
+
def test_might_happen
|
176
|
+
e = SampleErrorMightHappen.new('fbar')
|
177
|
+
assert !e.report?
|
178
|
+
end
|
151
179
|
end
|
152
180
|
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.7
|
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-22 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_object_translation.rb
|
229
230
|
- test/locales/en.yml
|
230
231
|
- test/test_standard_error.rb
|
231
232
|
- test/test_helper.rb
|
232
|
-
- test/test_object_translation.rb
|