coaster 1.1.0 → 1.3.2

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: c38985e1f47460405cf2cf2e4f9507d78dd0db1f45d939ad5768269f1e2a6e7a
4
- data.tar.gz: 5fcefde9af96868f10520648de4d775f58282d42d33e07e8abbbd76806328a93
3
+ metadata.gz: 25d78eb2f5780582358622b301ce8bc56b65a317bebf07bfdd5d719b18701cca
4
+ data.tar.gz: 9862b67c209853c1a049e5769e503167e0a76fe687ab479755e3272b052dca5d
5
5
  SHA512:
6
- metadata.gz: d682e58f09d22aff8992360821e7dffc4a02c057882fb9ba9b9603631d76600c591016c1543b2e561190b9c91354049bfeb907c663abe3523b22d1cfc53b0579
7
- data.tar.gz: f5e73571a6ede546e38c34c2145c96b3832888cc642bdc60c15e61ac5f91241359e66a5387b501c2f60b0c6153fdc1fb9facff4caf1ff98dfde35e4b2c1ea769
6
+ metadata.gz: c39ebfe2f732a1f44d0c9d4bdcd0b5a81c1a7fc6b3f76f150be78c83c4fccd6a90b6b4333efd91e0b57194462dd31c58c97bf8225ada59c01efcb3c43b4f313a
7
+ data.tar.gz: f9915989ceac91f5891ede0dd40ce66c7e4e26f2d6628e508123ee75cb7229e125fe0567576b26f8ecf5e1ab87445ede8699d88d313c431c3968dc2ac8a60090
@@ -20,7 +20,7 @@ module Coaster
20
20
  end
21
21
 
22
22
  def logger
23
- return @@logger if defined?(@@logger)
23
+ return @@logger if defined?(@@logger) && @@logger
24
24
  return Rails.logger if defined?(Rails)
25
25
  nil
26
26
  end
@@ -57,23 +57,23 @@ class StandardError
57
57
  msg = hash.delete(:m)
58
58
  msg = hash.delete(:msg) || msg
59
59
  msg = hash.delete(:message) || msg
60
+ hash[:description] ||= hash.delete(:desc) if hash[:desc].present?
60
61
  @fingerprint = hash.delete(:fingerprint) || hash.delete(:fingerprints)
61
62
  @tags = hash.delete(:tags) || hash.delete(:tag)
62
63
  @level = hash.delete(:level) || hash.delete(:severity) || @level
63
64
  @tkey = hash.delete(:tkey)
64
- msg = cause.message if msg.nil? && cause
65
65
  @attributes.merge!(hash)
66
66
  when String then
67
67
  msg = message
68
68
  when FalseClass, NilClass then
69
- msg = ''
69
+ msg = nil
70
70
  else
71
71
  msg = message
72
72
  end
73
73
 
74
74
  @fingerprint = [] unless @fingerprint.is_a?(Array)
75
75
  @tags = {} unless @tags.is_a?(Hash)
76
- msg ||= self.class._translate
76
+ msg = cause.message if msg.blank? && cause
77
77
  super(msg)
78
78
  end
79
79
 
@@ -125,10 +125,17 @@ class StandardError
125
125
  super
126
126
  end
127
127
 
128
+ def _translate_params
129
+ attributes
130
+ end
131
+
128
132
  # user friendly message, for overid
129
133
  def user_message
130
134
  return description if description.present?
131
- _translate
135
+ if tkey.present?
136
+ return _translate
137
+ end
138
+ message
132
139
  end
133
140
 
134
141
  # another user friendly messages
@@ -138,6 +145,15 @@ class StandardError
138
145
  attributes[:descriptions]
139
146
  end
140
147
 
148
+ # https://github.com/getsentry/sentry-ruby/blob/fbbc7a51ed10684d0e8b7bd9d2a1b65a7351c9ef/lib/raven/event.rb#L162
149
+ # sentry message use `to_s` method
150
+ # https://ruby-doc.org/core-2.5.1/Exception.html#method-i-to_s
151
+ alias to_origin_s to_s
152
+
153
+ def to_s
154
+ "#{_translate} (#{to_origin_s})"
155
+ end
156
+
141
157
  def to_hash
142
158
  hash = attributes.merge(
143
159
  type: self.class.name, status: status,
@@ -153,13 +169,6 @@ class StandardError
153
169
  hash
154
170
  end
155
171
 
156
- def _translate_params
157
- attributes.merge(
158
- type: self.class.name, status: status,
159
- http_status: http_status, message: message
160
- )
161
- end
162
-
163
172
  def to_json
164
173
  Oj.dump(to_hash.with_indifferent_access, mode: :compat)
165
174
  end
@@ -1,3 +1,3 @@
1
1
  module Coaster
2
- VERSION = '1.1.0'
2
+ VERSION = '1.3.2'
3
3
  end
@@ -18,3 +18,4 @@ en:
18
18
  title: 'Test this title'
19
19
  sample:
20
20
  title: 'Sample Title'
21
+ interpolation: 'Sample Interpolation %{value}'
@@ -21,60 +21,98 @@ module Coaster
21
21
  end
22
22
 
23
23
  def test_standard_messages
24
- e = StandardError.new('asdf')
25
- assert_equal 'asdf', e.message
24
+ e = StandardError.new('developer message')
25
+ assert_equal "standard error translation (developer message)", e.to_s
26
+ assert_equal "standard error translation (developer message)", e.message
26
27
  assert_nil e.description
27
28
  assert_nil e.desc
28
29
  assert_equal 'standard error translation', e._translate
29
- assert_equal 'standard error translation', e.user_message
30
+ assert_equal 'standard error translation (developer message)', e.user_message
30
31
  assert_equal 'standard error title', e.title
31
- e = StandardError.new(m: 'foo', desc: 'bar')
32
- assert_equal 'foo', e.message
33
- assert_equal 'bar', e.description
34
- assert_equal 'bar', e.desc
35
- assert_equal 'bar', e._translate
36
- assert_equal 'bar', e.user_message
32
+ e = StandardError.new(m: 'developer message', desc: 'user message')
33
+ assert_equal "user message (developer message)", e.to_s
34
+ assert_equal "user message (developer message)", e.message
35
+ assert_equal 'user message', e.description
36
+ assert_equal 'user message', e.desc
37
+ assert_equal 'user message', e._translate
38
+ assert_equal 'user message', e.user_message
37
39
  assert_equal 'standard error title', e.title
38
40
  end
39
41
 
40
42
  def test_no_translation_class
41
- e = UntitledError.new('asdf')
42
- assert_equal 'asdf', e.message
43
+ e = UntitledError.new('developer message')
44
+ assert_equal "standard error translation (developer message)", e.to_s
45
+ assert_equal "standard error translation (developer message)", e.message
43
46
  assert_nil e.description
44
47
  assert_nil e.desc
45
48
  assert_equal 'standard error translation', e._translate
46
- assert_equal 'standard error translation', e.user_message
49
+ assert_equal 'standard error translation (developer message)', e.user_message
47
50
  assert_equal 'standard error title', e.title
48
- e = UntitledError.new(m: 'foo', desc: 'bar')
49
- assert_equal 'foo', e.message
50
- assert_equal 'bar', e.description
51
- assert_equal 'bar', e.desc
52
- assert_equal 'bar', e._translate
53
- assert_equal 'bar', e.user_message
51
+ e = UntitledError.new(m: 'developer message', desc: 'user message')
52
+ assert_equal "user message (developer message)", e.to_s
53
+ assert_equal "user message (developer message)", e.message
54
+ assert_equal 'user message', e.description
55
+ assert_equal 'user message', e.desc
56
+ assert_equal 'user message', e._translate
57
+ assert_equal 'user message', e.user_message
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
54
66
  assert_equal 'standard error title', e.title
55
67
  end
56
68
 
57
69
  def test_with_translation_class
58
- e = SampleError.new('asdf')
59
- assert_equal 'asdf', e.message
70
+ e = SampleError.new
71
+ assert_equal "Test sample error (Coaster::TestStandardError::SampleError)", e.to_s
72
+ assert_equal "Test sample error (Coaster::TestStandardError::SampleError)", e.message
73
+ assert_nil e.description
74
+ assert_nil e.desc
75
+ assert_equal 'Test sample error', e._translate
76
+ assert_equal 'Test sample error (Coaster::TestStandardError::SampleError)', e.user_message
77
+ assert_equal 'Test this title', e.title
78
+ e = SampleError.new(beet: 'apple')
79
+ assert_equal "Test sample error (Coaster::TestStandardError::SampleError)", e.to_s
80
+ assert_equal "Test sample error (Coaster::TestStandardError::SampleError)", e.message
60
81
  assert_nil e.description
61
82
  assert_nil e.desc
62
83
  assert_equal 'Test sample error', e._translate
63
- assert_equal 'Test sample error', e.user_message
84
+ assert_equal 'Test sample error (Coaster::TestStandardError::SampleError)', e.user_message
85
+ assert_equal 'Test this title', e.title
86
+ e = SampleError.new('developer message')
87
+ assert_equal "Test sample error (developer message)", e.to_s
88
+ assert_equal "Test sample error (developer message)", e.message
89
+ assert_nil e.description
90
+ assert_nil e.desc
91
+ assert_equal 'Test sample error', e._translate
92
+ assert_equal 'Test sample error (developer message)', e.user_message
64
93
  assert_equal 'Test this title', e.title
65
- e = SampleError.new(m: 'foo', desc: 'bar')
66
- assert_equal 'foo', e.message
67
- assert_equal 'bar', e.description
68
- assert_equal 'bar', e.desc
69
- assert_equal 'bar', e._translate
70
- assert_equal 'bar', e.user_message
94
+ e = SampleError.new(m: 'developer message', desc: 'user message')
95
+ assert_equal "user message (developer message)", e.to_s
96
+ assert_equal "user message (developer message)", 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(tkey: 'sample.interpolation', value: 'blah')
103
+ assert_equal "Sample Interpolation blah (Coaster::TestStandardError::SampleError)", e.to_s
104
+ assert_equal "Sample Interpolation blah (Coaster::TestStandardError::SampleError)", e.message
105
+ assert_nil e.description
106
+ assert_nil e.desc
107
+ assert_equal 'Sample Interpolation blah', e._translate
108
+ assert_equal 'Sample Interpolation blah', e.user_message
71
109
  assert_equal 'Test this title', e.title
72
110
  end
73
111
 
74
112
  def test_message
75
113
  raise SampleError, {m: 'beer is proof'}
76
114
  rescue => e
77
- assert_equal 'beer is proof', e.message
115
+ assert_equal "Test sample error (beer is proof)", e.message
78
116
  end
79
117
 
80
118
  def test_attributes
@@ -94,12 +132,12 @@ module Coaster
94
132
  assert_equal 'Coaster::TestStandardError::ExampleError', e.to_hash['type']
95
133
  assert_equal 20, e.to_hash['status']
96
134
  assert_equal 500, e.to_hash['http_status']
97
- assert_equal 'Test sample error', e.to_hash['message']
135
+ assert_equal "Test example error (Test sample error (#{SampleError.name}))", e.to_hash['message']
98
136
  assert_equal 'rams', e.to_hash['cause']['frog']
99
137
  assert_equal 'Coaster::TestStandardError::SampleError', e.to_hash['cause']['type']
100
138
  assert_equal 10, e.to_hash['cause']['status']
101
139
  assert_equal 500, e.to_hash['cause']['http_status']
102
- assert_equal 'Test sample error', e.to_hash['cause']['message']
140
+ assert_equal "Test sample error (Coaster::TestStandardError::SampleError)", e.to_hash['cause']['message']
103
141
  end
104
142
 
105
143
  def test_cause_attributes
@@ -123,7 +161,7 @@ module Coaster
123
161
  rescue => e
124
162
  detail = <<-LOG
125
163
  [Coaster::TestStandardError::ExampleError] status:20
126
- MESSAGE: Test sample error
164
+ MESSAGE: Test example error (Test sample error (Coaster::TestStandardError::SampleError))
127
165
  @fingerprint: []
128
166
  @tags: {}
129
167
  @level: \"error\"
@@ -131,7 +169,7 @@ module Coaster
131
169
  @tkey: nil
132
170
  @raven: {}
133
171
  CAUSE: [Coaster::TestStandardError::SampleError] status:10
134
- MESSAGE: Test sample error
172
+ MESSAGE: Test sample error (Coaster::TestStandardError::SampleError)
135
173
  @fingerprint: []
136
174
  @tags: {}
137
175
  @level: \"error\"
@@ -180,7 +218,7 @@ LOG
180
218
  begin
181
219
  root_cause_sample3
182
220
  rescue => e
183
- assert_equal 'a', e.root_cause.message
221
+ assert_equal "standard error translation (a)", e.root_cause.message
184
222
  end
185
223
  end
186
224
 
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.1.0
4
+ version: 1.3.2
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-09-25 00:00:00.000000000 Z
11
+ date: 2020-10-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: i18n
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '3.0'
47
+ version: 6.0.3.1
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '3.0'
54
+ version: 6.0.3.1
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: attr_extras
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -70,114 +70,72 @@ dependencies:
70
70
  name: bundler
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: '1.12'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "~>"
81
- - !ruby/object:Gem::Version
82
- version: '1.12'
83
- - !ruby/object:Gem::Dependency
84
- name: pry
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - "~>"
88
- - !ruby/object:Gem::Version
89
- version: '0.8'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - "~>"
95
- - !ruby/object:Gem::Version
96
- version: '0.8'
97
- - !ruby/object:Gem::Dependency
98
- name: pry-stack_explorer
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - "~>"
102
- - !ruby/object:Gem::Version
103
- version: '0.4'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - "~>"
109
- - !ruby/object:Gem::Version
110
- version: '0.4'
111
- - !ruby/object:Gem::Dependency
112
- name: pry-byebug
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - "~>"
73
+ - - ">="
116
74
  - !ruby/object:Gem::Version
117
- version: '3.0'
75
+ version: '0'
118
76
  type: :development
119
77
  prerelease: false
120
78
  version_requirements: !ruby/object:Gem::Requirement
121
79
  requirements:
122
- - - "~>"
80
+ - - ">="
123
81
  - !ruby/object:Gem::Version
124
- version: '3.0'
82
+ version: '0'
125
83
  - !ruby/object:Gem::Dependency
126
84
  name: minitest
127
85
  requirement: !ruby/object:Gem::Requirement
128
86
  requirements:
129
- - - "~>"
87
+ - - ">="
130
88
  - !ruby/object:Gem::Version
131
- version: '5.0'
89
+ version: '0'
132
90
  type: :development
133
91
  prerelease: false
134
92
  version_requirements: !ruby/object:Gem::Requirement
135
93
  requirements:
136
- - - "~>"
94
+ - - ">="
137
95
  - !ruby/object:Gem::Version
138
- version: '5.0'
96
+ version: '0'
139
97
  - !ruby/object:Gem::Dependency
140
98
  name: mocha
141
99
  requirement: !ruby/object:Gem::Requirement
142
100
  requirements:
143
- - - "~>"
101
+ - - ">="
144
102
  - !ruby/object:Gem::Version
145
- version: '1.0'
103
+ version: '0'
146
104
  type: :development
147
105
  prerelease: false
148
106
  version_requirements: !ruby/object:Gem::Requirement
149
107
  requirements:
150
- - - "~>"
108
+ - - ">="
151
109
  - !ruby/object:Gem::Version
152
- version: '1.0'
110
+ version: '0'
153
111
  - !ruby/object:Gem::Dependency
154
112
  name: shoulda
155
113
  requirement: !ruby/object:Gem::Requirement
156
114
  requirements:
157
- - - "~>"
115
+ - - ">="
158
116
  - !ruby/object:Gem::Version
159
- version: '3.0'
117
+ version: '0'
160
118
  type: :development
161
119
  prerelease: false
162
120
  version_requirements: !ruby/object:Gem::Requirement
163
121
  requirements:
164
- - - "~>"
122
+ - - ">="
165
123
  - !ruby/object:Gem::Version
166
- version: '3.0'
124
+ version: '0'
167
125
  - !ruby/object:Gem::Dependency
168
126
  name: shoulda-context
169
127
  requirement: !ruby/object:Gem::Requirement
170
128
  requirements:
171
- - - "~>"
129
+ - - ">="
172
130
  - !ruby/object:Gem::Version
173
- version: '1.0'
131
+ version: '0'
174
132
  type: :development
175
133
  prerelease: false
176
134
  version_requirements: !ruby/object:Gem::Requirement
177
135
  requirements:
178
- - - "~>"
136
+ - - ">="
179
137
  - !ruby/object:Gem::Version
180
- version: '1.0'
138
+ version: '0'
181
139
  description: Ruby Core Extensions
182
140
  email: buzz@frograms.com
183
141
  executables: []
@@ -221,12 +179,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
221
179
  - !ruby/object:Gem::Version
222
180
  version: '0'
223
181
  requirements: []
224
- rubygems_version: 3.0.3
182
+ rubygems_version: 3.1.2
225
183
  signing_key:
226
184
  specification_version: 4
227
185
  summary: A little convenient feature for standard library
228
186
  test_files:
229
187
  - test/test_object_translation.rb
230
- - test/locales/en.yml
231
- - test/test_standard_error.rb
232
188
  - test/test_helper.rb
189
+ - test/test_standard_error.rb
190
+ - test/locales/en.yml