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 +4 -4
- data/lib/coaster/core_ext/standard_error.rb +21 -7
- data/lib/coaster/core_ext/standard_error/raven.rb +0 -13
- data/lib/coaster/version.rb +1 -1
- data/test/locales/en.yml +1 -0
- data/test/test_standard_error.rb +79 -39
- metadata +2 -44
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 33d174be37c41745be18836a83e051931f9c7eff099bc65d4bfbdb292e467732
|
4
|
+
data.tar.gz: 8c822b6bad5a1d334057a5cd577e8f236b201cfc74cd8ce6bd1c6586190880ab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
data/lib/coaster/version.rb
CHANGED
data/test/locales/en.yml
CHANGED
data/test/test_standard_error.rb
CHANGED
@@ -21,66 +21,106 @@ module Coaster
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def test_standard_messages
|
24
|
-
e = StandardError.new('
|
25
|
-
assert_equal
|
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: '
|
33
|
-
assert_equal
|
34
|
-
assert_equal
|
35
|
-
assert_equal '
|
36
|
-
assert_equal '
|
37
|
-
assert_equal '
|
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('
|
44
|
-
assert_equal
|
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: '
|
52
|
-
assert_equal
|
53
|
-
assert_equal
|
54
|
-
assert_equal '
|
55
|
-
assert_equal '
|
56
|
-
assert_equal '
|
57
|
-
assert_equal '
|
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
|
63
|
-
assert_equal
|
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
|
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(
|
71
|
-
assert_equal
|
72
|
-
assert_equal
|
73
|
-
|
74
|
-
|
75
|
-
assert_equal '
|
76
|
-
assert_equal '
|
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
|
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
|
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
|
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
|
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.
|
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-
|
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
|