coaster 1.3.11 → 1.3.14

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: acbec4ff07fe4d7c1dc23f17fef5d7e6cd6d04927b939a3cc4dd1f18d6b06ee6
4
- data.tar.gz: e6577b880b519901eeb33c0caa02a0064befb16828b07d4a444bbebfe94078e1
3
+ metadata.gz: a813e9a52472c914ad88ee95a1022645ffa3a93a2e921aebbb1ab5130b967f59
4
+ data.tar.gz: c1e74b7ff24af1484c97370c9eef806ffe0a7ca6ad140e818024ab110b4a69bc
5
5
  SHA512:
6
- metadata.gz: 64d8b9037c64e68d42d25f632d4d0b76f3b4adde43b8946e297b1fd1d34eee4e8c904a62b075f5e973b50ac57cc2e7f9644d64f014c052eb0fc788138ac988fa
7
- data.tar.gz: 2e53bfbe09a5c66cd88a1a56a7f8ad2eeede07dfea0a63d4aa20cdddf3dc070004ba7f8cd1b4c492d6013bf22328b71b7b1668e9d079b23572118e3602e3c692
6
+ metadata.gz: 90b871d5de0b4302cd686db1e1f4c3e11b39e1546420e61dd868b015bb47b20c84867f31d05ed7f274798efe24b6933dbfde42a54ae731478314946747441f7f
7
+ data.tar.gz: 5253a5d4a178e34c98193a296891ebb32e882531b802a65346b466c00a3e2961bf6400564c50202a9a15ac704ede90d7ccca47d66bc20636c6e3ce0ac32d4dfe
@@ -29,6 +29,14 @@ class StandardError
29
29
  end
30
30
  end
31
31
 
32
+ def user_digests_with!(&block)
33
+ define_method(:user_digests, &block)
34
+ end
35
+
36
+ def user_digests_with_default!
37
+ define_method(:user_digests) { _user_digests }
38
+ end
39
+
32
40
  def before_logging(name, &block)
33
41
  @before_logging_blocks ||= {}
34
42
  @before_logging_blocks[name] = block
@@ -55,21 +63,25 @@ class StandardError
55
63
  @tags = {}
56
64
  @level = 'error'
57
65
  @attributes = HashWithIndifferentAccess.new
58
- @attributes.merge!(cause.attributes || {}) if cause && cause.respond_to?(:attributes)
59
66
  @tkey = nil
67
+ if cause && cause.is_a?(StandardError)
68
+ @fingerprint = cause.fingerprint.dup
69
+ @tags = cause.tags.dup
70
+ @level = cause.level
71
+ @tkey = cause.tkey
72
+ @attributes = cause.attributes.dup
73
+ end
60
74
 
61
75
  case message
62
- when Exception
63
- msg = message
64
- set_backtrace(message.backtrace)
65
76
  when StandardError
66
- @fingerprint = message.fingerprint
67
- @tags = message.tags
77
+ @fingerprint = [message.fingerprint, @fingerprint].flatten.compact.uniq
78
+ @tags = @tags.merge(message.tags || {})
68
79
  @level = message.level
69
80
  @tkey = message.tkey
70
- @attributes = message.attributes
81
+ @attributes = @attributes.merge(message.attributes || {})
82
+ msg = message
83
+ when Exception
71
84
  msg = message
72
- set_backtrace(message.backtrace)
73
85
  when Hash then
74
86
  @coaster = true # coaster 확장을 사용한 에러임을 확인할 수 있음.
75
87
  hash = message.with_indifferent_access rescue message
@@ -100,6 +112,11 @@ class StandardError
100
112
  @tags = {} unless @tags.is_a?(Hash)
101
113
  msg = "{#{cause.message}}" if msg.blank? && cause
102
114
  super(msg)
115
+ set_backtrace(msg.backtrace) if msg.is_a?(Exception)
116
+ @fingerprint << digest_message
117
+ @fingerprint << digest_backtrace
118
+ @fingerprint.compact!
119
+ self
103
120
  end
104
121
 
105
122
  def safe_message; message || '' end
@@ -111,7 +128,8 @@ class StandardError
111
128
  @digest_message ||= Digest::MD5.hexdigest(m)[0...6]
112
129
  end
113
130
  def digest_backtrace; @digest_backtrace ||= backtrace ? Digest::MD5.hexdigest(cleaned_backtrace.join("\n"))[0...8] : nil end
114
- def user_digests; @user_digests ||= "#{[digest_message, digest_backtrace].compact.join(' ')}" end
131
+ def _user_digests; "#{[digest_message, digest_backtrace].compact.join(' ')}" end
132
+ alias_method :user_digests, :_user_digests
115
133
  def status; self.class.status end
116
134
  def before_logging_blocks; self.class.before_logging_blocks end
117
135
  def after_logging_blocks; self.class.after_logging_blocks end
@@ -165,7 +183,8 @@ class StandardError
165
183
  # user friendly message, for overid
166
184
  def user_message
167
185
  return _translate if description.present? || tkey.present?
168
- "#{_translate} (#{user_digests})"
186
+ return "#{_translate} (#{user_digests})" unless defined?(@coaster)
187
+ message
169
188
  rescue => e
170
189
  "#{message} (user_message_error - #{e.class.name} #{e.message})"
171
190
  end
@@ -1,3 +1,3 @@
1
1
  module Coaster
2
- VERSION = '1.3.11'
2
+ VERSION = '1.3.14'
3
3
  end
@@ -178,5 +178,34 @@ module Coaster
178
178
  end
179
179
  end
180
180
  end
181
+
182
+ def test_backtrace_to_keep
183
+ e = ArgumentError.new(m: 'blahasdf', desc: 'qwer')
184
+ new_e = StandardError.new(e)
185
+ assert_equal new_e.message, e.message
186
+ assert_equal new_e.description, e.description
187
+ assert_nil new_e.backtrace
188
+ assert_nil e.backtrace
189
+ end
190
+
191
+ def test_backtrace_to_keep_as_cause
192
+ raise ArgumentError, m: 'blahasdf', desc: 'qwer'
193
+ rescue => e
194
+ new_e = StandardError.new(e)
195
+ assert_equal new_e.message, e.message
196
+ assert_equal new_e.description, e.description
197
+ assert_equal new_e.backtrace, e.backtrace
198
+ end
199
+
200
+ def sample_method_for_sse
201
+ sample_method_for_sse
202
+ end
203
+
204
+ def test_system_stack_error
205
+ sample_method_for_sse
206
+ rescue SystemStackError => e
207
+ new_e = StandardError.new(e)
208
+ assert_equal new_e.backtrace, e.backtrace
209
+ end
181
210
  end
182
211
  end
@@ -88,7 +88,7 @@ module Coaster
88
88
  assert_nil e.description
89
89
  assert_nil e.desc
90
90
  assert_equal 'Test sample error', e._translate
91
- assert_equal 'Test sample error (cbe233)', e.user_message
91
+ assert_equal 'Test sample error (Coaster::TestStandardError::SampleError)', e.user_message
92
92
  assert_equal 'Test this title', e.title
93
93
  e = SampleError.new('developer message')
94
94
  assert_equal "developer message", e.to_s
@@ -199,7 +199,9 @@ module Coaster
199
199
  MESSAGE: Test example error (Coaster::TestStandardError::ExampleError) cause{Test sample error (Coaster::TestStandardError::SampleError)}
200
200
  @attributes: {\"frog\"=>\"rams\", \"wat\"=>\"cha\"}
201
201
  @coaster: true
202
- @fingerprint: []
202
+ @digest_backtrace: NilClass
203
+ @digest_message: a8c7c1
204
+ @fingerprint: ["a8c7c1"]
203
205
  @ins_var: [\"Coaster::TestStandardError::SampleError\", {\"h\"=>1}]
204
206
  @ins_varr: {\"dd\"=>true}
205
207
  @level: \"error\"
@@ -215,7 +217,9 @@ CAUSE: [Coaster::TestStandardError::SampleError] status:10
215
217
  MESSAGE: Test sample error (Coaster::TestStandardError::SampleError)
216
218
  @attributes: {"frog"=>"rams"}
217
219
  @coaster: true
218
- @fingerprint: []
220
+ @digest_backtrace: NilClass
221
+ @digest_message: cbe233
222
+ @fingerprint: ["cbe233"]
219
223
  @level: "error"
220
224
  @raven: {}
221
225
  @tags: {}
@@ -308,10 +312,11 @@ LOG
308
312
  def test_to_hash
309
313
  aa # raise NameError
310
314
  rescue => e
315
+ bt = e.digest_backtrace
311
316
  assert_equal 'NameError', e.to_hash['type']
312
317
  assert_equal 999999, e.to_hash['status']
313
318
  assert_equal 500, e.to_hash['http_status']
314
- assert_equal 'standard error translation (a962bd 80dfafa3)', e.user_message
319
+ assert_equal "standard error translation (a962bd #{bt})", e.user_message
315
320
  assert_match(/undefined local variable or method `aa'/, e.to_hash['message'])
316
321
  end
317
322
 
@@ -344,5 +349,36 @@ LOG
344
349
  e = SampleErrorMightHappen.new('fbar')
345
350
  assert !e.report?
346
351
  end
352
+
353
+ def test_user_message_change
354
+ SampleErrorSub.user_digests_with! do
355
+ message
356
+ end
357
+
358
+ begin
359
+ raise SampleError, 'asdff'
360
+ rescue => e
361
+ bt = e.digest_backtrace
362
+ assert_equal "Test sample error (0dba9e #{bt})", e.user_message
363
+ end
364
+ begin
365
+ raise SampleErrorSub, 'asdff'
366
+ rescue => e
367
+ assert_equal 'Test sample error (asdff)', e.user_message
368
+ end
369
+ begin
370
+ raise SampleErrorSubSub, 'asdff'
371
+ rescue => e
372
+ assert_equal 'Test sample error (asdff)', e.user_message
373
+ end
374
+
375
+ SampleErrorSubSub.user_digests_with_default!
376
+ begin
377
+ raise SampleErrorSubSub, 'asdff'
378
+ rescue => e
379
+ bt = e.digest_backtrace
380
+ assert_equal "Test sample error (58ee3f #{bt})", e.user_message
381
+ end
382
+ end
347
383
  end
348
384
  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.3.11
4
+ version: 1.3.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - buzz jung
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-06-15 00:00:00.000000000 Z
11
+ date: 2022-07-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: i18n
@@ -169,7 +169,7 @@ homepage: http://github.com/frograms/coaster
169
169
  licenses:
170
170
  - MIT
171
171
  metadata: {}
172
- post_install_message:
172
+ post_install_message:
173
173
  rdoc_options: []
174
174
  require_paths:
175
175
  - lib
@@ -184,14 +184,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
184
184
  - !ruby/object:Gem::Version
185
185
  version: '0'
186
186
  requirements: []
187
- rubygems_version: 3.1.6
188
- signing_key:
187
+ rubygems_version: 3.3.7
188
+ signing_key:
189
189
  specification_version: 4
190
190
  summary: A little convenient feature for standard library
191
191
  test_files:
192
192
  - test/locales/en.yml
193
- - test/test_standard_error.rb
194
- - test/test_month.rb
195
193
  - test/test_backtrace.rb
196
194
  - test/test_helper.rb
195
+ - test/test_month.rb
197
196
  - test/test_object_translation.rb
197
+ - test/test_standard_error.rb