coaster 1.3.0 → 1.3.5

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: aeeb91379c4231e8622891bfbfee5c93c202e96706bfa7d569b4bcea3e19d696
4
- data.tar.gz: 124f01130e4fadf67e9e28c134e409986f8d1186e324f1b93e35fdf040a09652
3
+ metadata.gz: ca831c98247a51e387740d4a2b15d9d7c31a37a4a119e69bf9081cc6ef08a438
4
+ data.tar.gz: dedfc0e5be84563640b98ac5808dda34c735ac2ca40edac5c76d906d69c9b63d
5
5
  SHA512:
6
- metadata.gz: fe9c0490709aa11a3c96816294702dbebd982b7304af0633f319612035f4be627f030a928749506d454fd2806c485b6e440c37c0895dae8ec2633a780a66f4dd
7
- data.tar.gz: 5a7de756347f74c4ece3dad9b36a987d44715b29cca55ded06d2a1bdfb0b38f4e16c654a4d9c2db3284c4cf76ab629afcbfa3bc33f373eeb21fc52db8008d6e0
6
+ metadata.gz: 4d8591789c4e587d37b88033881c6031d7ce231915058b2eac1b041c5e2d8933a03808a157a6f8cf17b3b5541c0ee25b1fd3b24992956467bfda165369c22968
7
+ data.tar.gz: f778ee607e1f0a249518df4292427e4fd812ebbca8868b40908e593dce6670d4a818b166a58aa24cb5f195f9159119983684ff1fee0cf6c2273bf02d54a949a6
@@ -53,6 +53,7 @@ class StandardError
53
53
  msg = message
54
54
  set_backtrace(message.backtrace)
55
55
  when Hash then
56
+ @coaster = true # coaster 확장을 사용한 에러임을 확인할 수 있음.
56
57
  hash = message.with_indifferent_access rescue message
57
58
  msg = hash.delete(:m)
58
59
  msg = hash.delete(:msg) || msg
@@ -63,6 +64,12 @@ class StandardError
63
64
  @level = hash.delete(:level) || hash.delete(:severity) || @level
64
65
  @tkey = hash.delete(:tkey)
65
66
  @attributes.merge!(hash)
67
+ if @attributes[:description] == :translate
68
+ @attributes.delete(:description)
69
+ @attributes[:description] = _translate
70
+ end
71
+ msg = "#{_translate} (#{msg || self.class.name})"
72
+ msg = "#{msg} {#{cause.message}}" if cause
66
73
  when String then
67
74
  msg = message
68
75
  when FalseClass, NilClass then
@@ -73,7 +80,7 @@ class StandardError
73
80
 
74
81
  @fingerprint = [] unless @fingerprint.is_a?(Array)
75
82
  @tags = {} unless @tags.is_a?(Hash)
76
- msg = cause.message if msg.blank? && cause
83
+ msg = "{#{cause.message}}" if msg.blank? && cause
77
84
  super(msg)
78
85
  end
79
86
 
@@ -115,9 +122,7 @@ class StandardError
115
122
 
116
123
  # description is user friendly message as a attribute, do not use error's message
117
124
  # error message is not user friendly in many cases.
118
- def description
119
- attributes[:description] || attributes[:desc]
120
- end
125
+ def description; attributes[:description] || attributes[:desc] end
121
126
  alias_method :desc, :description
122
127
 
123
128
  def _translate(*args)
@@ -131,8 +136,9 @@ class StandardError
131
136
 
132
137
  # user friendly message, for overid
133
138
  def user_message
134
- return description if description.present?
135
- _translate
139
+ return _translate if description.present? || tkey.present?
140
+ return "#{_translate} (#{message})" unless defined?(@coaster)
141
+ message
136
142
  end
137
143
 
138
144
  # another user friendly messages
@@ -142,15 +148,6 @@ class StandardError
142
148
  attributes[:descriptions]
143
149
  end
144
150
 
145
- # https://github.com/getsentry/sentry-ruby/blob/fbbc7a51ed10684d0e8b7bd9d2a1b65a7351c9ef/lib/raven/event.rb#L162
146
- # sentry message use `to_s` method
147
- # https://ruby-doc.org/core-2.5.1/Exception.html#method-i-to_s
148
- alias to_origin_s to_s
149
-
150
- def to_s
151
- "#{_translate}\n#{to_origin_s}"
152
- end
153
-
154
151
  def to_hash
155
152
  hash = attributes.merge(
156
153
  type: self.class.name, status: status,
@@ -174,7 +171,7 @@ class StandardError
174
171
  lg = "[#{self.class.name}] status:#{status}"
175
172
  lg += "\n\tMESSAGE: #{safe_message.gsub(/\n/, "\n\t\t")}"
176
173
  instance_variables.each do |var|
177
- if var.to_s.start_with?('@_')
174
+ if var.to_s.start_with?('@_') || var.to_s == '@coaster'
178
175
  next
179
176
  elsif var.to_s == '@spell_checker'
180
177
  next
@@ -1,3 +1,3 @@
1
1
  module Coaster
2
- VERSION = '1.3.0'
2
+ VERSION = '1.3.5'
3
3
  end
@@ -22,16 +22,16 @@ module Coaster
22
22
 
23
23
  def test_standard_messages
24
24
  e = StandardError.new('developer message')
25
- assert_equal "standard error translation\ndeveloper message", e.to_s
26
- assert_equal "standard error translation\ndeveloper message", e.message
25
+ assert_equal "developer message", e.to_s
26
+ assert_equal "developer message", e.message
27
27
  assert_nil e.description
28
28
  assert_nil e.desc
29
29
  assert_equal 'standard error translation', e._translate
30
- assert_equal 'standard error translation', e.user_message
30
+ assert_equal 'standard error translation (developer message)', e.user_message
31
31
  assert_equal 'standard error title', e.title
32
32
  e = StandardError.new(m: 'developer message', desc: 'user message')
33
- assert_equal "user message\ndeveloper message", e.to_s
34
- assert_equal "user message\ndeveloper message", e.message
33
+ assert_equal "user message (developer message)", e.to_s
34
+ assert_equal "user message (developer message)", e.message
35
35
  assert_equal 'user message', e.description
36
36
  assert_equal 'user message', e.desc
37
37
  assert_equal 'user message', e._translate
@@ -41,59 +41,83 @@ module Coaster
41
41
 
42
42
  def test_no_translation_class
43
43
  e = UntitledError.new('developer message')
44
- assert_equal "standard error translation\ndeveloper message", e.to_s
45
- assert_equal "standard error translation\ndeveloper message", e.message
44
+ assert_equal "developer message", e.to_s
45
+ assert_equal "developer message", e.message
46
46
  assert_nil e.description
47
47
  assert_nil e.desc
48
48
  assert_equal 'standard error translation', e._translate
49
- assert_equal 'standard error translation', e.user_message
49
+ assert_equal 'standard error translation (developer message)', e.user_message
50
50
  assert_equal 'standard error title', e.title
51
51
  e = UntitledError.new(m: 'developer message', desc: 'user message')
52
- assert_equal "user message\ndeveloper message", e.to_s
53
- assert_equal "user message\ndeveloper message", e.message
52
+ assert_equal "user message (developer message)", e.to_s
53
+ assert_equal "user message (developer message)", e.message
54
54
  assert_equal 'user message', e.description
55
55
  assert_equal 'user message', e.desc
56
56
  assert_equal 'user message', e._translate
57
57
  assert_equal 'user message', e.user_message
58
58
  assert_equal 'standard error title', e.title
59
+ e = UntitledError.new(tkey: 'no.translation')
60
+ assert_equal "translation missing: en.no.translation (Coaster::TestStandardError::UntitledError)", e.to_s
61
+ assert_equal "translation missing: en.no.translation (Coaster::TestStandardError::UntitledError)", e.message
62
+ assert_nil e.description
63
+ assert_nil e.desc
64
+ assert_equal 'translation missing: en.no.translation', e._translate
65
+ assert_equal "translation missing: en.no.translation", e.user_message
66
+ assert_equal 'standard error title', e.title
59
67
  end
60
68
 
61
69
  def test_with_translation_class
62
70
  e = SampleError.new
63
- assert_equal "Test sample error\nCoaster::TestStandardError::SampleError", e.to_s
64
- assert_equal "Test sample error\nCoaster::TestStandardError::SampleError", e.message
71
+ assert_equal "Coaster::TestStandardError::SampleError", e.to_s
72
+ assert_equal "Coaster::TestStandardError::SampleError", e.message
65
73
  assert_nil e.description
66
74
  assert_nil e.desc
67
75
  assert_equal 'Test sample error', e._translate
68
- assert_equal 'Test sample error', e.user_message
76
+ assert_equal 'Test sample error (Coaster::TestStandardError::SampleError)', e.user_message
69
77
  assert_equal 'Test this title', e.title
70
78
  e = SampleError.new(beet: 'apple')
71
- assert_equal "Test sample error\nCoaster::TestStandardError::SampleError", e.to_s
72
- assert_equal "Test sample error\nCoaster::TestStandardError::SampleError", e.message
79
+ assert_equal "Test sample error (Coaster::TestStandardError::SampleError)", e.to_s
80
+ assert_equal "Test sample error (Coaster::TestStandardError::SampleError)", e.message
73
81
  assert_nil e.description
74
82
  assert_nil e.desc
75
83
  assert_equal 'Test sample error', e._translate
76
- assert_equal 'Test sample error', e.user_message
84
+ assert_equal 'Test sample error (Coaster::TestStandardError::SampleError)', e.user_message
77
85
  assert_equal 'Test this title', e.title
78
86
  e = SampleError.new('developer message')
79
- assert_equal "Test sample error\ndeveloper message", e.to_s
80
- assert_equal "Test sample error\ndeveloper message", e.message
87
+ assert_equal "developer message", e.to_s
88
+ assert_equal "developer message", e.message
81
89
  assert_nil e.description
82
90
  assert_nil e.desc
83
91
  assert_equal 'Test sample error', e._translate
92
+ assert_equal 'Test sample error (developer message)', e.user_message
93
+ assert_equal 'Test this title', e.title
94
+ e = SampleError.new(desc: 'user message')
95
+ assert_equal "user message (Coaster::TestStandardError::SampleError)", e.to_s
96
+ assert_equal "user message (Coaster::TestStandardError::SampleError)", e.message
97
+ assert_equal 'user message', e.description
98
+ assert_equal 'user message', e.desc
99
+ assert_equal 'user message', e._translate
100
+ assert_equal 'user message', e.user_message
101
+ assert_equal 'Test this title', e.title
102
+ e = SampleError.new(m: 'developer message', desc: :translate)
103
+ assert_equal "Test sample error (developer message)", e.to_s
104
+ assert_equal "Test sample error (developer message)", e.message
105
+ assert_equal "Test sample error", e.description
106
+ assert_equal "Test sample error", e.desc
107
+ assert_equal 'Test sample error', e._translate
84
108
  assert_equal 'Test sample error', e.user_message
85
109
  assert_equal 'Test this title', e.title
86
110
  e = SampleError.new(m: 'developer message', desc: 'user message')
87
- assert_equal "user message\ndeveloper message", e.to_s
88
- assert_equal "user message\ndeveloper message", e.message
111
+ assert_equal "user message (developer message)", e.to_s
112
+ assert_equal "user message (developer message)", e.message
89
113
  assert_equal 'user message', e.description
90
114
  assert_equal 'user message', e.desc
91
115
  assert_equal 'user message', e._translate
92
116
  assert_equal 'user message', e.user_message
93
117
  assert_equal 'Test this title', e.title
94
118
  e = SampleError.new(tkey: 'sample.interpolation', value: 'blah')
95
- assert_equal "Sample Interpolation blah\nCoaster::TestStandardError::SampleError", e.to_s
96
- assert_equal "Sample Interpolation blah\nCoaster::TestStandardError::SampleError", e.message
119
+ assert_equal "Sample Interpolation blah (Coaster::TestStandardError::SampleError)", e.to_s
120
+ assert_equal "Sample Interpolation blah (Coaster::TestStandardError::SampleError)", e.message
97
121
  assert_nil e.description
98
122
  assert_nil e.desc
99
123
  assert_equal 'Sample Interpolation blah', e._translate
@@ -104,7 +128,7 @@ module Coaster
104
128
  def test_message
105
129
  raise SampleError, {m: 'beer is proof'}
106
130
  rescue => e
107
- assert_equal "Test sample error\nbeer is proof", e.message
131
+ assert_equal "Test sample error (beer is proof)", e.message
108
132
  end
109
133
 
110
134
  def test_attributes
@@ -124,21 +148,22 @@ module Coaster
124
148
  assert_equal 'Coaster::TestStandardError::ExampleError', e.to_hash['type']
125
149
  assert_equal 20, e.to_hash['status']
126
150
  assert_equal 500, e.to_hash['http_status']
127
- assert_equal "Test example error\nTest sample error\n#{SampleError.name}", e.to_hash['message']
151
+ assert_equal "Test example error (Coaster::TestStandardError::ExampleError) {Test sample error (Coaster::TestStandardError::SampleError)}", e.to_hash['message']
128
152
  assert_equal 'rams', e.to_hash['cause']['frog']
129
153
  assert_equal 'Coaster::TestStandardError::SampleError', e.to_hash['cause']['type']
130
154
  assert_equal 10, e.to_hash['cause']['status']
131
155
  assert_equal 500, e.to_hash['cause']['http_status']
132
- assert_equal "Test sample error\nCoaster::TestStandardError::SampleError", e.to_hash['cause']['message']
156
+ assert_equal "Test sample error (Coaster::TestStandardError::SampleError)", e.to_hash['cause']['message']
133
157
  end
134
158
 
135
159
  def test_cause_attributes
136
160
  begin
137
161
  raise SampleError, {frog: 'rams'}
138
162
  rescue => e
139
- raise ExampleError, {wat: 'cha'}
163
+ raise ExampleError, {m: 'abc', wat: 'cha'}
140
164
  end
141
165
  rescue => e
166
+ assert_equal 'Test example error (abc) {Test sample error (Coaster::TestStandardError::SampleError)}', e.message
142
167
  assert_equal 'rams', e.cause.attr['frog']
143
168
  assert_equal 'rams', e.attr['frog']
144
169
  assert_equal 'cha', e.attr['wat']
@@ -153,9 +178,7 @@ module Coaster
153
178
  rescue => e
154
179
  detail = <<-LOG
155
180
  [Coaster::TestStandardError::ExampleError] status:20
156
- MESSAGE: Test example error
157
- Test sample error
158
- Coaster::TestStandardError::SampleError
181
+ MESSAGE: Test example error (Coaster::TestStandardError::ExampleError) {Test sample error (Coaster::TestStandardError::SampleError)}
159
182
  @fingerprint: []
160
183
  @tags: {}
161
184
  @level: \"error\"
@@ -163,8 +186,7 @@ module Coaster
163
186
  @tkey: nil
164
187
  @raven: {}
165
188
  CAUSE: [Coaster::TestStandardError::SampleError] status:10
166
- MESSAGE: Test sample error
167
- Coaster::TestStandardError::SampleError
189
+ MESSAGE: Test sample error (Coaster::TestStandardError::SampleError)
168
190
  @fingerprint: []
169
191
  @tags: {}
170
192
  @level: \"error\"
@@ -213,7 +235,7 @@ LOG
213
235
  begin
214
236
  root_cause_sample3
215
237
  rescue => e
216
- assert_equal "standard error translation\na", e.root_cause.message
238
+ assert_equal "a", e.root_cause.message
217
239
  end
218
240
  end
219
241
 
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.0
4
+ version: 1.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: 2020-10-14 00:00:00.000000000 Z
11
+ date: 2020-10-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: i18n