coaster 1.2.1 → 1.3.3

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: c85271d1d65e61c492464d2e3bc610bad2fa784ba3da758e246c599ba655262c
4
- data.tar.gz: b2715ff440d638cdd164338a1c55b4c689cdad95e54a65b66c29d8ad5e7d7d75
3
+ metadata.gz: 33d174be37c41745be18836a83e051931f9c7eff099bc65d4bfbdb292e467732
4
+ data.tar.gz: 8c822b6bad5a1d334057a5cd577e8f236b201cfc74cd8ce6bd1c6586190880ab
5
5
  SHA512:
6
- metadata.gz: f74c50dce4b7d64a44ec89a67814d2ce2ee1b9c8b89b75aae0fe4dbe05182ac444ac7903f1a5585d227cdb890f566727506722c9878ed12bcd1a583aea42080f
7
- data.tar.gz: 19fd1dad72c06d49b5f3a380519a5f1ec7677c201d0485e6eceea866739513989decadafd396733dcffb66392b9ef8dd609feb2a510d307c9ab6e60e36a6faa8
6
+ metadata.gz: 58cfb38ecda73be57102b58e19d1badabc1a6ddf87717df4d8e6dc74b918fdf7f4e7d3569cffdb32968c3a5adc79b33930b14e534e6d1176656b22048a7a2951
7
+ data.tar.gz: 2886f1c69b87eda652641e8f28e48fb1514c8e8d1fe0d65973a93d63553426ea8dedd6012f27058b483f3ec293233e1468a1c67763a02ac1e0208804b9b1ff80
@@ -58,23 +58,23 @@ class StandardError
58
58
  msg = hash.delete(:msg) || msg
59
59
  msg = hash.delete(:message) || msg
60
60
  hash[:description] ||= hash.delete(:desc) if hash[:desc].present?
61
+ hash[:dev_message] ||= hash.delete(:dm) if hash[:dm].present?
61
62
  @fingerprint = hash.delete(:fingerprint) || hash.delete(:fingerprints)
62
63
  @tags = hash.delete(:tags) || hash.delete(:tag)
63
64
  @level = hash.delete(:level) || hash.delete(:severity) || @level
64
65
  @tkey = hash.delete(:tkey)
65
- msg = cause.message if msg.nil? && cause
66
66
  @attributes.merge!(hash)
67
67
  when String then
68
68
  msg = message
69
69
  when FalseClass, NilClass then
70
- msg = ''
70
+ msg = nil
71
71
  else
72
72
  msg = message
73
73
  end
74
74
 
75
75
  @fingerprint = [] unless @fingerprint.is_a?(Array)
76
76
  @tags = {} unless @tags.is_a?(Hash)
77
- msg ||= self.class._translate
77
+ msg = cause.message if msg.blank? && cause
78
78
  super(msg)
79
79
  end
80
80
 
@@ -116,20 +116,25 @@ class StandardError
116
116
 
117
117
  # description is user friendly message as a attribute, do not use error's message
118
118
  # error message is not user friendly in many cases.
119
- def description
120
- attributes[:description] || attributes[:desc]
121
- end
119
+ def description; attributes[:description] || attributes[:desc] end
122
120
  alias_method :desc, :description
121
+ def dev_message; attributes[:dev_message] end
122
+ alias_method :dm, :dev_message
123
123
 
124
124
  def _translate(*args)
125
125
  return description if description.present?
126
126
  super
127
127
  end
128
128
 
129
+ def _translate_params
130
+ attributes
131
+ end
132
+
129
133
  # user friendly message, for overid
130
134
  def user_message
131
135
  return description if description.present?
132
- _translate
136
+ return _translate if tkey.present?
137
+ "#{_translate} (#{to_origin_s})"
133
138
  end
134
139
 
135
140
  # another user friendly messages
@@ -139,6 +144,15 @@ class StandardError
139
144
  attributes[:descriptions]
140
145
  end
141
146
 
147
+ # https://github.com/getsentry/sentry-ruby/blob/fbbc7a51ed10684d0e8b7bd9d2a1b65a7351c9ef/lib/raven/event.rb#L162
148
+ # sentry message use `to_s` method
149
+ # https://ruby-doc.org/core-2.5.1/Exception.html#method-i-to_s
150
+ alias to_origin_s to_s
151
+
152
+ def to_s
153
+ "#{_translate} (#{dev_message || to_origin_s})"
154
+ end
155
+
142
156
  def to_hash
143
157
  hash = attributes.merge(
144
158
  type: self.class.name, status: status,
@@ -66,17 +66,4 @@ class StandardError
66
66
  capture(options)
67
67
  just_logging(options)
68
68
  end
69
-
70
- # https://github.com/getsentry/sentry-ruby/blob/fbbc7a51ed10684d0e8b7bd9d2a1b65a7351c9ef/lib/raven/event.rb#L162
71
- # sentry use `to_s` as a message
72
- alias to_origin_s to_s
73
- def message
74
- to_origin_s
75
- end
76
-
77
- def to_s
78
- str = super # https://ruby-doc.org/core-2.5.1/Exception.html#method-i-to_s
79
- str = "#{user_message} / #{str}" if user_message.present?
80
- str
81
- end
82
69
  end
@@ -1,3 +1,3 @@
1
1
  module Coaster
2
- VERSION = '1.2.1'
2
+ VERSION = '1.3.3'
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,66 +21,106 @@ 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 / asdf', e.to_s
30
+ assert_equal 'standard error translation (developer message)', e.user_message
31
31
  assert_equal 'standard error title', e.title
32
- e = StandardError.new(m: 'foo', desc: 'bar')
33
- assert_equal 'foo', e.message
34
- assert_equal 'bar', e.description
35
- assert_equal 'bar', e.desc
36
- assert_equal 'bar', e._translate
37
- 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
38
39
  assert_equal 'standard error title', e.title
39
- assert_equal 'bar / foo', e.to_s
40
40
  end
41
41
 
42
42
  def test_no_translation_class
43
- e = UntitledError.new('asdf')
44
- 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
45
46
  assert_nil e.description
46
47
  assert_nil e.desc
47
48
  assert_equal 'standard error translation', e._translate
48
- assert_equal 'standard error translation', e.user_message
49
- assert_equal 'standard error translation / asdf', e.to_s
49
+ assert_equal 'standard error translation (developer message)', e.user_message
50
50
  assert_equal 'standard error title', e.title
51
- e = UntitledError.new(m: 'foo', desc: 'bar')
52
- assert_equal 'foo', e.message
53
- assert_equal 'bar', e.description
54
- assert_equal 'bar', e.desc
55
- assert_equal 'bar', e._translate
56
- assert_equal 'bar', e.user_message
57
- assert_equal 'bar / foo', e.to_s
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
58
66
  assert_equal 'standard error title', e.title
59
67
  end
60
68
 
61
69
  def test_with_translation_class
62
- e = SampleError.new('asdf')
63
- 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
81
+ assert_nil e.description
82
+ assert_nil e.desc
83
+ assert_equal 'Test sample error', e._translate
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
93
+ assert_equal 'Test this title', e.title
94
+ e = SampleError.new(dm: 'developer message')
95
+ assert_equal "Test sample error (developer message)", e.to_s
96
+ assert_equal "Test sample error (developer message)", e.message
64
97
  assert_nil e.description
65
98
  assert_nil e.desc
66
99
  assert_equal 'Test sample error', e._translate
67
- assert_equal 'Test sample error', e.user_message
68
- assert_equal 'Test sample error / asdf', e.to_s
100
+ assert_equal 'Test sample error (Coaster::TestStandardError::SampleError)', e.user_message
101
+ assert_equal 'Test this title', e.title
102
+ e = SampleError.new(m: 'developer message', desc: 'user message')
103
+ assert_equal "user message (developer message)", e.to_s
104
+ assert_equal "user message (developer message)", e.message
105
+ assert_equal 'user message', e.description
106
+ assert_equal 'user message', e.desc
107
+ assert_equal 'user message', e._translate
108
+ assert_equal 'user message', e.user_message
69
109
  assert_equal 'Test this title', e.title
70
- e = SampleError.new(m: 'foo', desc: 'bar')
71
- assert_equal 'foo', e.message
72
- assert_equal 'bar', e.description
73
- assert_equal 'bar', e.desc
74
- assert_equal 'bar', e._translate
75
- assert_equal 'bar', e.user_message
76
- assert_equal 'bar / foo', e.to_s
110
+ e = SampleError.new(tkey: 'sample.interpolation', value: 'blah')
111
+ assert_equal "Sample Interpolation blah (Coaster::TestStandardError::SampleError)", e.to_s
112
+ assert_equal "Sample Interpolation blah (Coaster::TestStandardError::SampleError)", e.message
113
+ assert_nil e.description
114
+ assert_nil e.desc
115
+ assert_equal 'Sample Interpolation blah', e._translate
116
+ assert_equal 'Sample Interpolation blah', e.user_message
77
117
  assert_equal 'Test this title', e.title
78
118
  end
79
119
 
80
120
  def test_message
81
121
  raise SampleError, {m: 'beer is proof'}
82
122
  rescue => e
83
- assert_equal 'beer is proof', e.message
123
+ assert_equal "Test sample error (beer is proof)", e.message
84
124
  end
85
125
 
86
126
  def test_attributes
@@ -100,12 +140,12 @@ module Coaster
100
140
  assert_equal 'Coaster::TestStandardError::ExampleError', e.to_hash['type']
101
141
  assert_equal 20, e.to_hash['status']
102
142
  assert_equal 500, e.to_hash['http_status']
103
- assert_equal 'Test sample error', e.to_hash['message']
143
+ assert_equal "Test example error (Test sample error (#{SampleError.name}))", e.to_hash['message']
104
144
  assert_equal 'rams', e.to_hash['cause']['frog']
105
145
  assert_equal 'Coaster::TestStandardError::SampleError', e.to_hash['cause']['type']
106
146
  assert_equal 10, e.to_hash['cause']['status']
107
147
  assert_equal 500, e.to_hash['cause']['http_status']
108
- assert_equal 'Test sample error', e.to_hash['cause']['message']
148
+ assert_equal "Test sample error (Coaster::TestStandardError::SampleError)", e.to_hash['cause']['message']
109
149
  end
110
150
 
111
151
  def test_cause_attributes
@@ -129,7 +169,7 @@ module Coaster
129
169
  rescue => e
130
170
  detail = <<-LOG
131
171
  [Coaster::TestStandardError::ExampleError] status:20
132
- MESSAGE: Test sample error
172
+ MESSAGE: Test example error (Test sample error (Coaster::TestStandardError::SampleError))
133
173
  @fingerprint: []
134
174
  @tags: {}
135
175
  @level: \"error\"
@@ -137,7 +177,7 @@ module Coaster
137
177
  @tkey: nil
138
178
  @raven: {}
139
179
  CAUSE: [Coaster::TestStandardError::SampleError] status:10
140
- MESSAGE: Test sample error
180
+ MESSAGE: Test sample error (Coaster::TestStandardError::SampleError)
141
181
  @fingerprint: []
142
182
  @tags: {}
143
183
  @level: \"error\"
@@ -186,7 +226,7 @@ LOG
186
226
  begin
187
227
  root_cause_sample3
188
228
  rescue => e
189
- assert_equal 'a', e.root_cause.message
229
+ assert_equal "standard error translation (a)", e.root_cause.message
190
230
  end
191
231
  end
192
232
 
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.2.1
4
+ version: 1.3.3
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-13 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
@@ -80,48 +80,6 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
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'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: '0'
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'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - ">="
109
- - !ruby/object:Gem::Version
110
- version: '0'
111
- - !ruby/object:Gem::Dependency
112
- name: pry-byebug
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - ">="
116
- - !ruby/object:Gem::Version
117
- version: '0'
118
- type: :development
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - ">="
123
- - !ruby/object:Gem::Version
124
- version: '0'
125
83
  - !ruby/object:Gem::Dependency
126
84
  name: minitest
127
85
  requirement: !ruby/object:Gem::Requirement