coaster 1.2.2 → 1.3.4
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 +17 -7
- data/lib/coaster/core_ext/standard_error/raven.rb +0 -13
- data/lib/coaster/version.rb +1 -1
- data/test/test_standard_error.rb +72 -40
- metadata +2 -58
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '095940670cdfde3eac7e9c3ab8818386b9070cf4d19ac405e144296e2bdb2c25'
|
4
|
+
data.tar.gz: 468278966fcdad4349921586d9520a2dd0b84188f52f5f089678f09b88ea7ef8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a332cd5b18dd1963a010293352c80939d99c968f4c83d52f02aebf0d50d444eb2ed82ed0590afded4eed2712b58eb550b7ca1f1f90389d42011b920435a7929
|
7
|
+
data.tar.gz: 4fe3cddcca27bc17f0c189e9eb829b68f52f07b9a4b4c6c2a9dcbbaca883c2d2cb4e89f134c159fc0a94888049ac990dbb6c26d7811681f32d995a4e8dcbc22d
|
@@ -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,10 +116,10 @@ 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?
|
@@ -133,7 +133,8 @@ class StandardError
|
|
133
133
|
# user friendly message, for overid
|
134
134
|
def user_message
|
135
135
|
return description if description.present?
|
136
|
-
_translate
|
136
|
+
return _translate if tkey.present? || dev_message.present?
|
137
|
+
"#{_translate} (#{to_origin_s})"
|
137
138
|
end
|
138
139
|
|
139
140
|
# another user friendly messages
|
@@ -143,6 +144,15 @@ class StandardError
|
|
143
144
|
attributes[:descriptions]
|
144
145
|
end
|
145
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
|
+
|
146
156
|
def to_hash
|
147
157
|
hash = attributes.merge(
|
148
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/test_standard_error.rb
CHANGED
@@ -21,74 +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
100
|
assert_equal 'Test sample error', e.user_message
|
68
|
-
assert_equal 'Test sample error / asdf', e.to_s
|
69
101
|
assert_equal 'Test this title', e.title
|
70
|
-
e = SampleError.new(m: '
|
71
|
-
assert_equal
|
72
|
-
assert_equal
|
73
|
-
assert_equal '
|
74
|
-
assert_equal '
|
75
|
-
assert_equal '
|
76
|
-
assert_equal '
|
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
|
77
109
|
assert_equal 'Test this title', e.title
|
78
110
|
e = SampleError.new(tkey: 'sample.interpolation', value: 'blah')
|
79
|
-
assert_equal
|
111
|
+
assert_equal "Sample Interpolation blah (Coaster::TestStandardError::SampleError)", e.to_s
|
112
|
+
assert_equal "Sample Interpolation blah (Coaster::TestStandardError::SampleError)", e.message
|
80
113
|
assert_nil e.description
|
81
114
|
assert_nil e.desc
|
82
115
|
assert_equal 'Sample Interpolation blah', e._translate
|
83
116
|
assert_equal 'Sample Interpolation blah', e.user_message
|
84
|
-
assert_equal 'Sample Interpolation blah / Test sample error', e.to_s
|
85
117
|
assert_equal 'Test this title', e.title
|
86
118
|
end
|
87
119
|
|
88
120
|
def test_message
|
89
121
|
raise SampleError, {m: 'beer is proof'}
|
90
122
|
rescue => e
|
91
|
-
assert_equal
|
123
|
+
assert_equal "Test sample error (beer is proof)", e.message
|
92
124
|
end
|
93
125
|
|
94
126
|
def test_attributes
|
@@ -108,12 +140,12 @@ module Coaster
|
|
108
140
|
assert_equal 'Coaster::TestStandardError::ExampleError', e.to_hash['type']
|
109
141
|
assert_equal 20, e.to_hash['status']
|
110
142
|
assert_equal 500, e.to_hash['http_status']
|
111
|
-
assert_equal
|
143
|
+
assert_equal "Test example error (Test sample error (#{SampleError.name}))", e.to_hash['message']
|
112
144
|
assert_equal 'rams', e.to_hash['cause']['frog']
|
113
145
|
assert_equal 'Coaster::TestStandardError::SampleError', e.to_hash['cause']['type']
|
114
146
|
assert_equal 10, e.to_hash['cause']['status']
|
115
147
|
assert_equal 500, e.to_hash['cause']['http_status']
|
116
|
-
assert_equal
|
148
|
+
assert_equal "Test sample error (Coaster::TestStandardError::SampleError)", e.to_hash['cause']['message']
|
117
149
|
end
|
118
150
|
|
119
151
|
def test_cause_attributes
|
@@ -137,7 +169,7 @@ module Coaster
|
|
137
169
|
rescue => e
|
138
170
|
detail = <<-LOG
|
139
171
|
[Coaster::TestStandardError::ExampleError] status:20
|
140
|
-
MESSAGE: Test sample error
|
172
|
+
MESSAGE: Test example error (Test sample error (Coaster::TestStandardError::SampleError))
|
141
173
|
@fingerprint: []
|
142
174
|
@tags: {}
|
143
175
|
@level: \"error\"
|
@@ -145,7 +177,7 @@ module Coaster
|
|
145
177
|
@tkey: nil
|
146
178
|
@raven: {}
|
147
179
|
CAUSE: [Coaster::TestStandardError::SampleError] status:10
|
148
|
-
MESSAGE: Test sample error
|
180
|
+
MESSAGE: Test sample error (Coaster::TestStandardError::SampleError)
|
149
181
|
@fingerprint: []
|
150
182
|
@tags: {}
|
151
183
|
@level: \"error\"
|
@@ -194,7 +226,7 @@ LOG
|
|
194
226
|
begin
|
195
227
|
root_cause_sample3
|
196
228
|
rescue => e
|
197
|
-
assert_equal
|
229
|
+
assert_equal "standard error translation (a)", e.root_cause.message
|
198
230
|
end
|
199
231
|
end
|
200
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.4
|
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,62 +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
|
-
- !ruby/object:Gem::Dependency
|
126
|
-
name: pry-doc
|
127
|
-
requirement: !ruby/object:Gem::Requirement
|
128
|
-
requirements:
|
129
|
-
- - ">="
|
130
|
-
- !ruby/object:Gem::Version
|
131
|
-
version: '0'
|
132
|
-
type: :development
|
133
|
-
prerelease: false
|
134
|
-
version_requirements: !ruby/object:Gem::Requirement
|
135
|
-
requirements:
|
136
|
-
- - ">="
|
137
|
-
- !ruby/object:Gem::Version
|
138
|
-
version: '0'
|
139
83
|
- !ruby/object:Gem::Dependency
|
140
84
|
name: minitest
|
141
85
|
requirement: !ruby/object:Gem::Requirement
|