coaster 1.3.3 → 1.3.7
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/require_more.rb +22 -0
- data/lib/coaster/core_ext/standard_error/sentry.rb +69 -0
- data/lib/coaster/core_ext/standard_error.rb +12 -17
- data/lib/coaster/core_ext.rb +1 -0
- data/lib/coaster/version.rb +1 -1
- data/test/test_standard_error.rb +32 -16
- metadata +11 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 03f82d0ec684919dbdd18695f9c9b44accf45defa3260b7fcfeaadaf511b5869
|
4
|
+
data.tar.gz: 963dd53ba23fe26a009308b6065d25d58ec0a32713980479840f86d4fd71ed71
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ce52bb11a0aa053e521ff7261b079ae47e424846ecb7937596112cb5ec2a42b56a0f13afddb222a1c1bc333685f94c9fc97478865067fd44b1ce9eb5596515be
|
7
|
+
data.tar.gz: 7b6278654542c48270b3c817d1bf15f404da41c0bf36d546f9f7dac2f229a322c119fe0760690acd7011511433808a8fa228e8d62b53300cb21fc0bb9a3af9a9
|
@@ -0,0 +1,22 @@
|
|
1
|
+
def require_more
|
2
|
+
required_file_path = caller[0].split(':', 2).first
|
3
|
+
load_name = nil
|
4
|
+
load_path_index = $LOAD_PATH.each_with_index do |load_path, ix|
|
5
|
+
scanned = required_file_path.scan(/(#{load_path})#{File::SEPARATOR}(.*)/).first
|
6
|
+
next false unless scanned
|
7
|
+
load_name = scanned[1]
|
8
|
+
break ix
|
9
|
+
end
|
10
|
+
|
11
|
+
return false unless load_path_index
|
12
|
+
|
13
|
+
more_load_paths = $LOAD_PATH.drop(load_path_index + 1)
|
14
|
+
more_load_paths.each do |load_path|
|
15
|
+
path = File.join(load_path, load_name)
|
16
|
+
if File.exists?(path)
|
17
|
+
return require_dependency path
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
raise LoadError, "cannot require more -- #{load_name}"
|
22
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
class StandardError
|
2
|
+
attr_writer :raven
|
3
|
+
|
4
|
+
alias_method :initialize_original, :initialize
|
5
|
+
def initialize(message = nil, cause = $!)
|
6
|
+
initialize_original(message, cause)
|
7
|
+
@raven = (attributes.delete(:raven) || attributes.delete(:sentry) || {}).with_indifferent_access
|
8
|
+
end
|
9
|
+
|
10
|
+
def raven
|
11
|
+
@raven ||= {}.with_indifferent_access
|
12
|
+
end
|
13
|
+
|
14
|
+
def raven_fingerprint
|
15
|
+
(fingerprint || Coaster.default_fingerprint).flatten.map do |fp|
|
16
|
+
if fp == true || fp == :class
|
17
|
+
self.class.name
|
18
|
+
elsif fp == :default
|
19
|
+
'{{ default }}'
|
20
|
+
else
|
21
|
+
fp
|
22
|
+
end
|
23
|
+
end.flatten
|
24
|
+
end
|
25
|
+
|
26
|
+
def notes(options = {})
|
27
|
+
opts = options ? options.dup : {}
|
28
|
+
extra_opts = opts.slice!(:fingerprint, :tags, :level, :extra)
|
29
|
+
opts[:extra] = extra_opts.merge(opts[:extra] || {})
|
30
|
+
nt = raven.merge(opts)
|
31
|
+
|
32
|
+
nt[:tags] ||= (tags && tags.merge(nt[:tags] || {})) || {}
|
33
|
+
nt[:tags] = nt[:tags].merge(environment: Rails.env) if defined?(Rails)
|
34
|
+
nt[:level] ||= self.level
|
35
|
+
nt[:extra] = attributes.merge(nt[:extra])
|
36
|
+
nt
|
37
|
+
end
|
38
|
+
|
39
|
+
def capture(options = {})
|
40
|
+
return if options.key?(:report) && !options[:report]
|
41
|
+
return unless report?
|
42
|
+
nt = notes(options)
|
43
|
+
Sentry.capture_exception(self, level: nt[:level]) do |scope|
|
44
|
+
scope.user.merge!(nt[:user] || {})
|
45
|
+
scope.tags.merge!(nt[:tags])
|
46
|
+
scope.extra.merge!(nt[:extra])
|
47
|
+
scope.fingerprint = raven_fingerprint
|
48
|
+
end
|
49
|
+
rescue => e
|
50
|
+
msg = "#{e.class.name}: #{e.message}"
|
51
|
+
msg += "\n\t" + e.backtrace.join("\n\t")
|
52
|
+
Sentry.logger.error(msg)
|
53
|
+
end
|
54
|
+
|
55
|
+
# options
|
56
|
+
# :logger
|
57
|
+
# :cleaner
|
58
|
+
# :fingerprint
|
59
|
+
# :tags
|
60
|
+
# :level
|
61
|
+
# :extra
|
62
|
+
# :report
|
63
|
+
# and others are merged to extra
|
64
|
+
alias_method :just_logging, :logging
|
65
|
+
def logging(options = {})
|
66
|
+
capture(options)
|
67
|
+
just_logging(options)
|
68
|
+
end
|
69
|
+
end
|
@@ -53,17 +53,23 @@ 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
|
59
60
|
msg = hash.delete(:message) || msg
|
60
61
|
hash[:description] ||= hash.delete(:desc) if hash[:desc].present?
|
61
|
-
hash[:dev_message] ||= hash.delete(:dm) if hash[:dm].present?
|
62
62
|
@fingerprint = hash.delete(:fingerprint) || hash.delete(:fingerprints)
|
63
63
|
@tags = hash.delete(:tags) || hash.delete(:tag)
|
64
64
|
@level = hash.delete(:level) || hash.delete(:severity) || @level
|
65
65
|
@tkey = hash.delete(:tkey)
|
66
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
|
67
73
|
when String then
|
68
74
|
msg = message
|
69
75
|
when FalseClass, NilClass then
|
@@ -74,7 +80,7 @@ class StandardError
|
|
74
80
|
|
75
81
|
@fingerprint = [] unless @fingerprint.is_a?(Array)
|
76
82
|
@tags = {} unless @tags.is_a?(Hash)
|
77
|
-
msg = cause.message if msg.blank? && cause
|
83
|
+
msg = "{#{cause.message}}" if msg.blank? && cause
|
78
84
|
super(msg)
|
79
85
|
end
|
80
86
|
|
@@ -118,8 +124,6 @@ class StandardError
|
|
118
124
|
# error message is not user friendly in many cases.
|
119
125
|
def description; attributes[:description] || attributes[:desc] end
|
120
126
|
alias_method :desc, :description
|
121
|
-
def dev_message; attributes[:dev_message] end
|
122
|
-
alias_method :dm, :dev_message
|
123
127
|
|
124
128
|
def _translate(*args)
|
125
129
|
return description if description.present?
|
@@ -132,9 +136,9 @@ class StandardError
|
|
132
136
|
|
133
137
|
# user friendly message, for overid
|
134
138
|
def user_message
|
135
|
-
return
|
136
|
-
return _translate
|
137
|
-
|
139
|
+
return _translate if description.present? || tkey.present?
|
140
|
+
return "#{_translate} (#{message})" unless defined?(@coaster)
|
141
|
+
message
|
138
142
|
end
|
139
143
|
|
140
144
|
# another user friendly messages
|
@@ -144,15 +148,6 @@ class StandardError
|
|
144
148
|
attributes[:descriptions]
|
145
149
|
end
|
146
150
|
|
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
|
-
|
156
151
|
def to_hash
|
157
152
|
hash = attributes.merge(
|
158
153
|
type: self.class.name, status: status,
|
@@ -176,7 +171,7 @@ class StandardError
|
|
176
171
|
lg = "[#{self.class.name}] status:#{status}"
|
177
172
|
lg += "\n\tMESSAGE: #{safe_message.gsub(/\n/, "\n\t\t")}"
|
178
173
|
instance_variables.each do |var|
|
179
|
-
if var.to_s.start_with?('@_')
|
174
|
+
if var.to_s.start_with?('@_') || var.to_s == '@coaster'
|
180
175
|
next
|
181
176
|
elsif var.to_s == '@spell_checker'
|
182
177
|
next
|
data/lib/coaster/core_ext.rb
CHANGED
data/lib/coaster/version.rb
CHANGED
data/test/test_standard_error.rb
CHANGED
@@ -22,8 +22,8 @@ module Coaster
|
|
22
22
|
|
23
23
|
def test_standard_messages
|
24
24
|
e = StandardError.new('developer message')
|
25
|
-
assert_equal "
|
26
|
-
assert_equal "
|
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
|
@@ -41,8 +41,8 @@ module Coaster
|
|
41
41
|
|
42
42
|
def test_no_translation_class
|
43
43
|
e = UntitledError.new('developer message')
|
44
|
-
assert_equal "
|
45
|
-
assert_equal "
|
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
|
@@ -68,8 +68,8 @@ module Coaster
|
|
68
68
|
|
69
69
|
def test_with_translation_class
|
70
70
|
e = SampleError.new
|
71
|
-
assert_equal "
|
72
|
-
assert_equal "
|
71
|
+
assert_equal "Coaster::TestStandardError::SampleError", e.to_s
|
72
|
+
assert_equal "Coaster::TestStandardError::SampleError", e.message
|
73
73
|
assert_nil e.description
|
74
74
|
assert_nil e.desc
|
75
75
|
assert_equal 'Test sample error', e._translate
|
@@ -84,21 +84,36 @@ module Coaster
|
|
84
84
|
assert_equal 'Test sample error (Coaster::TestStandardError::SampleError)', e.user_message
|
85
85
|
assert_equal 'Test this title', e.title
|
86
86
|
e = SampleError.new('developer message')
|
87
|
-
assert_equal "
|
88
|
-
assert_equal "
|
87
|
+
assert_equal "developer message", e.to_s
|
88
|
+
assert_equal "developer message", e.message
|
89
89
|
assert_nil e.description
|
90
90
|
assert_nil e.desc
|
91
91
|
assert_equal 'Test sample error', e._translate
|
92
92
|
assert_equal 'Test sample error (developer message)', e.user_message
|
93
93
|
assert_equal 'Test this title', e.title
|
94
|
-
e = SampleError.new(
|
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)
|
95
103
|
assert_equal "Test sample error (developer message)", e.to_s
|
96
104
|
assert_equal "Test sample error (developer message)", e.message
|
97
|
-
|
98
|
-
|
105
|
+
assert_equal "Test sample error", e.description
|
106
|
+
assert_equal "Test sample error", e.desc
|
99
107
|
assert_equal 'Test sample error', e._translate
|
100
|
-
assert_equal 'Test sample error
|
108
|
+
assert_equal 'Test sample error', e.user_message
|
101
109
|
assert_equal 'Test this title', e.title
|
110
|
+
e = SampleError.new(desc: :translate)
|
111
|
+
assert_equal "Test sample error (Coaster::TestStandardError::SampleError)", e.to_s
|
112
|
+
assert_equal "Test sample error (Coaster::TestStandardError::SampleError)", e.message
|
113
|
+
assert_equal "Test sample error", e.description
|
114
|
+
assert_equal "Test sample error", e.desc
|
115
|
+
assert_equal "Test sample error", e._translate
|
116
|
+
assert_equal "Test sample error", e.user_message
|
102
117
|
e = SampleError.new(m: 'developer message', desc: 'user message')
|
103
118
|
assert_equal "user message (developer message)", e.to_s
|
104
119
|
assert_equal "user message (developer message)", e.message
|
@@ -140,7 +155,7 @@ module Coaster
|
|
140
155
|
assert_equal 'Coaster::TestStandardError::ExampleError', e.to_hash['type']
|
141
156
|
assert_equal 20, e.to_hash['status']
|
142
157
|
assert_equal 500, e.to_hash['http_status']
|
143
|
-
assert_equal "Test example error (Test sample error (
|
158
|
+
assert_equal "Test example error (Coaster::TestStandardError::ExampleError) {Test sample error (Coaster::TestStandardError::SampleError)}", e.to_hash['message']
|
144
159
|
assert_equal 'rams', e.to_hash['cause']['frog']
|
145
160
|
assert_equal 'Coaster::TestStandardError::SampleError', e.to_hash['cause']['type']
|
146
161
|
assert_equal 10, e.to_hash['cause']['status']
|
@@ -152,9 +167,10 @@ module Coaster
|
|
152
167
|
begin
|
153
168
|
raise SampleError, {frog: 'rams'}
|
154
169
|
rescue => e
|
155
|
-
raise ExampleError, {wat: 'cha'}
|
170
|
+
raise ExampleError, {m: 'abc', wat: 'cha'}
|
156
171
|
end
|
157
172
|
rescue => e
|
173
|
+
assert_equal 'Test example error (abc) {Test sample error (Coaster::TestStandardError::SampleError)}', e.message
|
158
174
|
assert_equal 'rams', e.cause.attr['frog']
|
159
175
|
assert_equal 'rams', e.attr['frog']
|
160
176
|
assert_equal 'cha', e.attr['wat']
|
@@ -169,7 +185,7 @@ module Coaster
|
|
169
185
|
rescue => e
|
170
186
|
detail = <<-LOG
|
171
187
|
[Coaster::TestStandardError::ExampleError] status:20
|
172
|
-
MESSAGE: Test example error (Test sample error (Coaster::TestStandardError::SampleError)
|
188
|
+
MESSAGE: Test example error (Coaster::TestStandardError::ExampleError) {Test sample error (Coaster::TestStandardError::SampleError)}
|
173
189
|
@fingerprint: []
|
174
190
|
@tags: {}
|
175
191
|
@level: \"error\"
|
@@ -226,7 +242,7 @@ LOG
|
|
226
242
|
begin
|
227
243
|
root_cause_sample3
|
228
244
|
rescue => e
|
229
|
-
assert_equal "
|
245
|
+
assert_equal "a", e.root_cause.message
|
230
246
|
end
|
231
247
|
end
|
232
248
|
|
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.
|
4
|
+
version: 1.3.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- buzz jung
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-11-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: i18n
|
@@ -152,8 +152,10 @@ files:
|
|
152
152
|
- lib/coaster/core_ext/date.rb
|
153
153
|
- lib/coaster/core_ext/month.rb
|
154
154
|
- lib/coaster/core_ext/object_translation.rb
|
155
|
+
- lib/coaster/core_ext/require_more.rb
|
155
156
|
- lib/coaster/core_ext/standard_error.rb
|
156
157
|
- lib/coaster/core_ext/standard_error/raven.rb
|
158
|
+
- lib/coaster/core_ext/standard_error/sentry.rb
|
157
159
|
- lib/coaster/serialized_properties.rb
|
158
160
|
- lib/coaster/version.rb
|
159
161
|
- test/locales/en.yml
|
@@ -164,7 +166,7 @@ homepage: http://github.com/frograms/coaster
|
|
164
166
|
licenses:
|
165
167
|
- MIT
|
166
168
|
metadata: {}
|
167
|
-
post_install_message:
|
169
|
+
post_install_message:
|
168
170
|
rdoc_options: []
|
169
171
|
require_paths:
|
170
172
|
- lib
|
@@ -179,12 +181,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
179
181
|
- !ruby/object:Gem::Version
|
180
182
|
version: '0'
|
181
183
|
requirements: []
|
182
|
-
rubygems_version: 3.1.
|
183
|
-
signing_key:
|
184
|
+
rubygems_version: 3.1.6
|
185
|
+
signing_key:
|
184
186
|
specification_version: 4
|
185
187
|
summary: A little convenient feature for standard library
|
186
188
|
test_files:
|
187
|
-
- test/test_object_translation.rb
|
188
|
-
- test/test_helper.rb
|
189
|
-
- test/test_standard_error.rb
|
190
189
|
- test/locales/en.yml
|
190
|
+
- test/test_standard_error.rb
|
191
|
+
- test/test_helper.rb
|
192
|
+
- test/test_object_translation.rb
|