Exception: StandardError
- Defined in:
- lib/coaster/core_ext/standard_error.rb,
lib/coaster/core_ext/standard_error/raven.rb,
lib/coaster/core_ext/standard_error/sentry.rb
Direct Known Subclasses
Coaster::SerializedProperties::DuplicatedProperty, Coaster::SerializedProperties::InvalidProperty
Constant Summary collapse
- DEFAULT_INSPECTION_VARS =
%i[@attributes @tkey @fingerprint @tags @level]
- DEFAULT_INSPECTION_VALUE_PROC =
Proc.new{|val| val.inspect}
Class Attribute Summary collapse
Instance Attribute Summary collapse
-
#fingerprint ⇒ Array
(also: #rails_tag, #sentry_fingerprint, #raven_fingerprint)
Fingerprint.
-
#level ⇒ Object
Returns the value of attribute level.
- #raven ⇒ Object
-
#sentry_event ⇒ Object
readonly
Returns the value of attribute sentry_event.
- #tags ⇒ Object
-
#tkey ⇒ Object
Returns the value of attribute tkey.
Class Method Summary collapse
- .after_logging(name, &block) ⇒ Object
- .after_logging_blocks ⇒ Object
- .before_logging(name, &block) ⇒ Object
- .before_logging_blocks ⇒ Object
-
.code ⇒ Object
Unknown.
- .digest_message(message) ⇒ Object
- .http_status ⇒ Object
- .inspection_value_simple(val) ⇒ Object
- .inspection_vars ⇒ Object
- .intentional? ⇒ Boolean
- .report? ⇒ Boolean
-
.status ⇒ Object
Unknown.
- .title ⇒ Object
- .user_digests_with!(&block) ⇒ Object
- .user_digests_with_default! ⇒ Object
Instance Method Summary collapse
- #_translate(*args) ⇒ Object
- #_translate_params ⇒ Object
- #_user_digests ⇒ Object (also: #user_digests)
- #after_logging_blocks ⇒ Object
- #attributes ⇒ Object (also: #attr)
- #before_logging_blocks ⇒ Object
- #capture(options = {}) ⇒ Object
- #cleaned_backtrace(options = {}) ⇒ Object
- #code ⇒ Object
- #code=(value) ⇒ Object
-
#description ⇒ Object
(also: #desc)
description is user friendly message as a attribute, do not use error’s message error message is not user friendly in many cases.
-
#descriptions ⇒ Object
another user friendly messages.
- #detail ⇒ Object
- #digest_backtrace ⇒ Object
- #digest_message ⇒ Object
- #http_status ⇒ Object
- #http_status=(value) ⇒ Object
-
#initialize(message = nil, cause = $!) ⇒ StandardError
constructor
A new instance of StandardError.
-
#initialize_original ⇒ StandardError
A new instance of StandardError.
- #inspection_value_proc ⇒ Object
- #inspection_vars ⇒ Object
-
#intentional? ⇒ Boolean
not logging in test.
- #it_might_happen? ⇒ Boolean
- #it_should_not_happen? ⇒ Boolean
-
#just_logging ⇒ Object
options :logger :cleaner :fingerprint :tags :level :extra :report and others are merged to extra.
- #logging(options = {}) ⇒ Object
- #notes(options = {}) ⇒ Object
- #object ⇒ Object (also: #obj)
- #report? ⇒ Boolean
- #root_cause ⇒ Object
- #safe_message ⇒ Object
- #sentry_event_id ⇒ Object
- #status ⇒ Object
- #title ⇒ Object
- #to_hash(_h: {}.with_indifferent_access, _depth: 0) ⇒ Object
- #to_inspection_hash(options: {}, _h: {}.with_indifferent_access, _depth: 0) ⇒ Object
- #to_inspection_ivars ⇒ Object
- #to_inspection_s(options: {}, _dh: nil) ⇒ Object (also: #to_detail)
- #to_json(options = {}) ⇒ Object
-
#user_message ⇒ Object
user friendly message, for overid.
Constructor Details
#initialize(message = nil, cause = $!) ⇒ StandardError
Returns a new instance of StandardError.
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/coaster/core_ext/standard_error.rb', line 69 def initialize( = nil, cause = $!) @fingerprint = [] @tags = {} @level = 'error' @attributes = HashWithIndifferentAccess.new @tkey = nil if cause && cause.is_a?(StandardError) @fingerprint = cause.fingerprint.dup @tags = cause..dup @level = cause.level @tkey = cause.tkey @attributes = cause.attributes.dup end case when StandardError @fingerprint = [.fingerprint, @fingerprint].flatten.compact.uniq @tags = @tags.merge(. || {}) @level = .level @tkey = .tkey @attributes = @attributes.merge(.attributes || {}) msg = . when Exception msg = . when Hash then @coaster = true # coaster 확장을 사용한 에러임을 확인할 수 있음. hash = .with_indifferent_access rescue msg = hash.delete(:m) msg = hash.delete(:msg) || msg msg = hash.delete(:message) || msg hash[:description] ||= hash.delete(:desc) if hash[:desc].present? @fingerprint = Array.wrap(hash.delete(:fingerprint) || hash.delete(:fingerprints)) + @fingerprint @tags = hash.delete(:tags) || hash.delete(:tag) @level = hash.delete(:level) || hash.delete(:severity) || @level @tkey = hash.delete(:tkey) @attributes.merge!(hash) if @attributes[:description] == :translate @attributes.delete(:description) @attributes[:description] = _translate end msg = "#{_translate} (#{msg || self.class.name})" msg = "#{msg} cause{#{cause.}}" if cause when String then msg = when FalseClass, NilClass then msg = nil else msg = end @fingerprint = [] unless @fingerprint.is_a?(Array) @tags = {} unless @tags.is_a?(Hash) msg = "{#{cause.}}" if msg.blank? && cause super(msg) @digest_message = self.class.(msg) set_backtrace(.backtrace) if .is_a?(Exception) @fingerprint.compact! self end |
Class Attribute Details
.inspection_value_proc ⇒ Object
22 |
# File 'lib/coaster/core_ext/standard_error.rb', line 22 def inspection_value_proc; @inspection_value_proc ||= superclass.respond_to?(:inspection_value_proc) ? superclass.inspection_value_proc : DEFAULT_INSPECTION_VALUE_PROC end |
Instance Attribute Details
#fingerprint ⇒ Array Also known as: rails_tag, sentry_fingerprint, raven_fingerprint
Returns fingerprint.
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/coaster/core_ext/standard_error.rb', line 130 def fingerprint if @fingerprint&.instance_variable_get(:@__processed__) @fingerprint else @fingerprint = ((@fingerprint || []) + Coaster.default_fingerprint).flatten.compact.map do |fp| case fp when Symbol then send(fp) when Proc then fp.call(self) when Numeric then fp else fp.to_s end rescue => e @fingerprint_exception = {msg: e., bt: e.backtrace ? e.backtrace[0..5] : nil} if fp.is_a?(Proc) && fp.source_location f = fp.source_location[0].split('/').last(3).join('/') "#{f}:#{fp.source_location[1]}" else fp.to_s end end.flatten.compact @fingerprint.instance_variable_set(:@__processed__, true) @fingerprint end end |
#level ⇒ Object
Returns the value of attribute level.
66 67 68 |
# File 'lib/coaster/core_ext/standard_error.rb', line 66 def level @level end |
#raven ⇒ Object
10 11 12 |
# File 'lib/coaster/core_ext/standard_error/raven.rb', line 10 def raven @raven ||= {}.with_indifferent_access end |
#sentry_event ⇒ Object (readonly)
Returns the value of attribute sentry_event.
3 4 5 |
# File 'lib/coaster/core_ext/standard_error/sentry.rb', line 3 def sentry_event @sentry_event end |
#tags ⇒ Object
156 |
# File 'lib/coaster/core_ext/standard_error.rb', line 156 def = @tags ||= {} |
#tkey ⇒ Object
Returns the value of attribute tkey.
66 67 68 |
# File 'lib/coaster/core_ext/standard_error.rb', line 66 def tkey @tkey end |
Class Method Details
.after_logging(name, &block) ⇒ Object
56 57 58 59 |
# File 'lib/coaster/core_ext/standard_error.rb', line 56 def after_logging(name, &block) @after_logging_blocks ||= {} @after_logging_blocks[name] = block end |
.after_logging_blocks ⇒ Object
60 61 62 63 |
# File 'lib/coaster/core_ext/standard_error.rb', line 60 def after_logging_blocks @after_logging_blocks ||= {} superclass <= StandardError ? superclass.after_logging_blocks.merge(@after_logging_blocks) : @after_logging_blocks end |
.before_logging(name, &block) ⇒ Object
47 48 49 50 |
# File 'lib/coaster/core_ext/standard_error.rb', line 47 def before_logging(name, &block) @before_logging_blocks ||= {} @before_logging_blocks[name] = block end |
.before_logging_blocks ⇒ Object
51 52 53 54 |
# File 'lib/coaster/core_ext/standard_error.rb', line 51 def before_logging_blocks @before_logging_blocks ||= {} superclass <= StandardError ? superclass.before_logging_blocks.merge(@before_logging_blocks) : @before_logging_blocks end |
.code ⇒ Object
Unknown
16 |
# File 'lib/coaster/core_ext/standard_error.rb', line 16 def status; 999999 end |
.digest_message(message) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/coaster/core_ext/standard_error.rb', line 31 def () m = .to_s.dup mat = m.match(/#\<.*0x(?<object_id>\S+)[\s\>]/) m = .gsub(/#{mat[:object_id]}/, 'X'*mat[:object_id].size) if mat m = "#{name} #{m}" Digest::MD5.hexdigest(m)[0...6] end |
.http_status ⇒ Object
17 |
# File 'lib/coaster/core_ext/standard_error.rb', line 17 def http_status; 500 end |
.inspection_value_simple(val) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/coaster/core_ext/standard_error.rb', line 23 def inspection_value_simple(val) case val when Array then val.map{|v| inspection_value_simple(v)} when Hash then Hash[val.map{|k,v| [k, inspection_value_simple(v)]}] when String, Numeric, TrueClass, FalseClass then val else val.class.name end end |
.inspection_vars ⇒ Object
21 |
# File 'lib/coaster/core_ext/standard_error.rb', line 21 def inspection_vars; @inspection_vars ||= DEFAULT_INSPECTION_VARS.dup end |
.intentional? ⇒ Boolean
19 |
# File 'lib/coaster/core_ext/standard_error.rb', line 19 def intentional?; false end |
.report? ⇒ Boolean
18 |
# File 'lib/coaster/core_ext/standard_error.rb', line 18 def report?; true end |
.status ⇒ Object
Unknown
15 |
# File 'lib/coaster/core_ext/standard_error.rb', line 15 def status; 999999 end |
.title ⇒ Object
20 |
# File 'lib/coaster/core_ext/standard_error.rb', line 20 def title; _translate('.title') end |
.user_digests_with!(&block) ⇒ Object
39 40 41 |
# File 'lib/coaster/core_ext/standard_error.rb', line 39 def user_digests_with!(&block) define_method(:user_digests, &block) end |
.user_digests_with_default! ⇒ Object
43 44 45 |
# File 'lib/coaster/core_ext/standard_error.rb', line 43 def user_digests_with_default! define_method(:user_digests) { _user_digests } end |
Instance Method Details
#_translate(*args) ⇒ Object
203 204 205 206 |
# File 'lib/coaster/core_ext/standard_error.rb', line 203 def _translate(*args) return description if description.present? super end |
#_translate_params ⇒ Object
208 209 210 |
# File 'lib/coaster/core_ext/standard_error.rb', line 208 def _translate_params attributes end |
#_user_digests ⇒ Object Also known as: user_digests
160 |
# File 'lib/coaster/core_ext/standard_error.rb', line 160 def _user_digests; "#{[, digest_backtrace].compact.join(' ')}" end |
#after_logging_blocks ⇒ Object
164 |
# File 'lib/coaster/core_ext/standard_error.rb', line 164 def after_logging_blocks; self.class.after_logging_blocks end |
#attributes ⇒ Object Also known as: attr
167 168 169 170 171 172 173 174 |
# File 'lib/coaster/core_ext/standard_error.rb', line 167 def attributes return @attributes if defined?(@attributes) @attributes = HashWithIndifferentAccess.new if cause && cause.respond_to?(:attributes) && cause.attributes.is_a?(Hash) @attributes = @attributes.merge(cause.attributes) end @attributes end |
#before_logging_blocks ⇒ Object
163 |
# File 'lib/coaster/core_ext/standard_error.rb', line 163 def before_logging_blocks; self.class.before_logging_blocks end |
#capture(options = {}) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/coaster/core_ext/standard_error/raven.rb', line 39 def capture( = {}) return if .key?(:report) && ![:report] return unless report? nt = notes() Raven.capture_exception(self, level: nt[:level]) do |event| event.user.merge!(nt[:user] || {}) event..merge!(nt[:tags]) event.extra.merge!(nt[:extra]) event.fingerprint = raven_fingerprint end rescue => e msg = "#{e.class.name}: #{e.}" msg += "\n\t" + e.backtrace.join("\n\t") Raven.logger.error(msg) end |
#cleaned_backtrace(options = {}) ⇒ Object
333 334 335 336 337 338 339 340 |
# File 'lib/coaster/core_ext/standard_error.rb', line 333 def cleaned_backtrace( = {}) return unless backtrace cl = [:cleaner] || cleaner return backtrace unless cl bt = cl.clean(backtrace) bt = bt[0..2] if intentional? bt end |
#code ⇒ Object
179 |
# File 'lib/coaster/core_ext/standard_error.rb', line 179 def code; attributes[:code] || status end |
#code=(value) ⇒ Object
180 |
# File 'lib/coaster/core_ext/standard_error.rb', line 180 def code=(value); attributes[:code] = value end |
#description ⇒ Object Also known as: desc
description is user friendly message as a attribute, do not use error’s message error message is not user friendly in many cases.
200 |
# File 'lib/coaster/core_ext/standard_error.rb', line 200 def description; attributes[:description] || attributes[:desc] end |
#descriptions ⇒ Object
another user friendly messages
222 223 224 225 226 |
# File 'lib/coaster/core_ext/standard_error.rb', line 222 def descriptions return attributes[:descriptions] if attributes[:descriptions] attributes[:descriptions] = {} attributes[:descriptions] end |
#detail ⇒ Object
182 |
# File 'lib/coaster/core_ext/standard_error.rb', line 182 def detail; attributes[:detail] end |
#digest_backtrace ⇒ Object
159 |
# File 'lib/coaster/core_ext/standard_error.rb', line 159 def digest_backtrace; @digest_backtrace ||= backtrace ? Digest::MD5.hexdigest(cleaned_backtrace.join("\n"))[0...8] : nil end |
#digest_message ⇒ Object
158 |
# File 'lib/coaster/core_ext/standard_error.rb', line 158 def ; @digest_message ||= self.class.() end |
#http_status ⇒ Object
177 |
# File 'lib/coaster/core_ext/standard_error.rb', line 177 def http_status; attributes[:http_status] || self.class.http_status end |
#http_status=(value) ⇒ Object
178 |
# File 'lib/coaster/core_ext/standard_error.rb', line 178 def http_status=(value); attributes[:http_status] = value end |
#initialize_original ⇒ StandardError
Returns a new instance of StandardError.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/coaster/core_ext/standard_error/raven.rb', line 4 def initialize( = nil, cause = $!) @fingerprint = [] @tags = {} @level = 'error' @attributes = HashWithIndifferentAccess.new @tkey = nil if cause && cause.is_a?(StandardError) @fingerprint = cause.fingerprint.dup @tags = cause..dup @level = cause.level @tkey = cause.tkey @attributes = cause.attributes.dup end case when StandardError @fingerprint = [.fingerprint, @fingerprint].flatten.compact.uniq @tags = @tags.merge(. || {}) @level = .level @tkey = .tkey @attributes = @attributes.merge(.attributes || {}) msg = . when Exception msg = . when Hash then @coaster = true # coaster 확장을 사용한 에러임을 확인할 수 있음. hash = .with_indifferent_access rescue msg = hash.delete(:m) msg = hash.delete(:msg) || msg msg = hash.delete(:message) || msg hash[:description] ||= hash.delete(:desc) if hash[:desc].present? @fingerprint = Array.wrap(hash.delete(:fingerprint) || hash.delete(:fingerprints)) + @fingerprint @tags = hash.delete(:tags) || hash.delete(:tag) @level = hash.delete(:level) || hash.delete(:severity) || @level @tkey = hash.delete(:tkey) @attributes.merge!(hash) if @attributes[:description] == :translate @attributes.delete(:description) @attributes[:description] = _translate end msg = "#{_translate} (#{msg || self.class.name})" msg = "#{msg} cause{#{cause.}}" if cause when String then msg = when FalseClass, NilClass then msg = nil else msg = end @fingerprint = [] unless @fingerprint.is_a?(Array) @tags = {} unless @tags.is_a?(Hash) msg = "{#{cause.}}" if msg.blank? && cause super(msg) @digest_message = self.class.(msg) set_backtrace(.backtrace) if .is_a?(Exception) @fingerprint.compact! self end |
#inspection_value_proc ⇒ Object
252 253 254 |
# File 'lib/coaster/core_ext/standard_error.rb', line 252 def inspection_value_proc attributes[:inspection_value_proc] || self.class.inspection_value_proc end |
#inspection_vars ⇒ Object
248 249 250 |
# File 'lib/coaster/core_ext/standard_error.rb', line 248 def inspection_vars (self.class.inspection_vars + (attributes[:inspection_vars] || [])).map(&:to_sym).compact.uniq end |
#intentional? ⇒ Boolean
not logging in test
190 191 192 193 194 |
# File 'lib/coaster/core_ext/standard_error.rb', line 190 def intentional? # not logging in test return attributes[:intentional] if attributes.key?(:intentional) return true if it_should_not_happen? self.class.intentional? end |
#it_might_happen? ⇒ Boolean
183 |
# File 'lib/coaster/core_ext/standard_error.rb', line 183 def it_might_happen?; attributes[:it] == :might_happen end |
#it_should_not_happen? ⇒ Boolean
184 |
# File 'lib/coaster/core_ext/standard_error.rb', line 184 def it_should_not_happen?; attributes[:it] == :should_not_happen end |
#just_logging ⇒ Object
options
:logger
:cleaner
:fingerprint
:tags
:level
:extra
:report
and others are merged to extra
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/coaster/core_ext/standard_error/raven.rb', line 64 def logging( = {}) before_logging_blocks.values.each { |blk| instance_exec(&blk) } if !report? || intentional? if defined?(Rails) return if Rails.env.test? else return end end logger = [:logger] || Coaster.logger return unless logger msg = to_inspection_s(options: ) if level && logger.respond_to?(level) logger.send(level, msg) else logger.error(msg) end msg ensure after_logging_blocks.values.each { |blk| instance_exec(&blk) } end |
#logging(options = {}) ⇒ Object
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 |
# File 'lib/coaster/core_ext/standard_error.rb', line 342 def logging( = {}) before_logging_blocks.values.each { |blk| instance_exec(&blk) } if !report? || intentional? if defined?(Rails) return if Rails.env.test? else return end end logger = [:logger] || Coaster.logger return unless logger msg = to_inspection_s(options: ) if level && logger.respond_to?(level) logger.send(level, msg) else logger.error(msg) end msg ensure after_logging_blocks.values.each { |blk| instance_exec(&blk) } end |
#notes(options = {}) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/coaster/core_ext/standard_error/raven.rb', line 26 def notes( = {}) opts = ? .dup : {} extra_opts = opts.slice!(:fingerprint, :tags, :level, :extra) opts[:extra] = extra_opts.merge(opts[:extra] || {}) nt = raven.merge(opts) nt[:tags] ||= ( && .merge(nt[:tags] || {})) || {} nt[:tags] = nt[:tags].merge(environment: Rails.env) if defined?(Rails) nt[:level] ||= self.level nt[:extra] = attributes.merge(nt[:extra]) nt end |
#object ⇒ Object Also known as: obj
195 |
# File 'lib/coaster/core_ext/standard_error.rb', line 195 def object; attributes[:object] || attributes[:obj] end |
#report? ⇒ Boolean
185 186 187 188 189 |
# File 'lib/coaster/core_ext/standard_error.rb', line 185 def report? return attributes[:report] if attributes.key?(:report) return false if it_might_happen? self.class.report? end |
#root_cause ⇒ Object
165 |
# File 'lib/coaster/core_ext/standard_error.rb', line 165 def root_cause; cause.respond_to?(:root_cause) ? cause.root_cause : self end |
#safe_message ⇒ Object
157 |
# File 'lib/coaster/core_ext/standard_error.rb', line 157 def ; || '' end |
#sentry_event_id ⇒ Object
50 51 52 |
# File 'lib/coaster/core_ext/standard_error/sentry.rb', line 50 def sentry_event_id @sentry_event&.event_id end |
#status ⇒ Object
162 |
# File 'lib/coaster/core_ext/standard_error.rb', line 162 def status; self.class.status end |
#title ⇒ Object
181 |
# File 'lib/coaster/core_ext/standard_error.rb', line 181 def title; attributes[:title] || self.class.title end |
#to_hash(_h: {}.with_indifferent_access, _depth: 0) ⇒ Object
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 |
# File 'lib/coaster/core_ext/standard_error.rb', line 228 def to_hash(_h: {}.with_indifferent_access, _depth: 0) _h.merge!(attributes) _h.merge!( type: self.class.name, status: status, http_status: http_status, message: ) if _depth < 4 && cause if cause.respond_to?(:to_hash) _h[:cause] = cause.to_hash(_depth: _depth + 1) else _h[:cause_object] = cause end end _h end |
#to_inspection_hash(options: {}, _h: {}.with_indifferent_access, _depth: 0) ⇒ Object
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 |
# File 'lib/coaster/core_ext/standard_error.rb', line 273 def to_inspection_hash(options: {}, _h: {}.with_indifferent_access, _depth: 0) backtrace_key = [:backtrace_key] || :backtrace _h.merge!( type: self.class.name, status: status, http_status: http_status, message: , instance_variables: {}.with_indifferent_access ) digest_backtrace # for @digest_backtrace _h.merge!(to_inspection_ivars) if backtrace.present? if respond_to?(:cleaned_backtrace) if (bt = cleaned_backtrace()) _h[backtrace_key] = bt else _h[backtrace_key] = backtrace[0...ActiveSupport::BacktraceCleaner.minimum_first] end else _h[backtrace_key] = backtrace[0...ActiveSupport::BacktraceCleaner.minimum_first] end end if cause if _depth < 4 if cause.respond_to?(:to_inspection_hash) _h[:cause] = cause.to_inspection_hash(options: , _depth: _depth + 1) else cause_h = { type: self.class.name, status: status, http_status: http_status, message: , } cause_h.merge!(backtrace_key => cause.backtrace[0...ActiveSupport::BacktraceCleaner.minimum_first]) _h[:cause] = cause_h end else _h[:cause] = 'and more causes...' end end _h end |
#to_inspection_ivars ⇒ Object
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 |
# File 'lib/coaster/core_ext/standard_error.rb', line 256 def to_inspection_ivars _h = {instance_variables: {}}.with_indifferent_access instance_variables.sort.each do |var| if inspection_vars.include?(var) val = instance_variable_get(var) val = inspection_value_proc.call(val) rescue val.to_s _h[:instance_variables][var] = val elsif var.to_s.start_with?('@__') next else val = instance_variable_get(var) _h[:instance_variables][var] = self.class.inspection_value_simple(val) end end _h end |
#to_inspection_s(options: {}, _dh: nil) ⇒ Object Also known as: to_detail
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 |
# File 'lib/coaster/core_ext/standard_error.rb', line 312 def to_inspection_s(options: {}, _dh: nil) dh = _dh || to_inspection_hash(options: , _h: {}.with_indifferent_access, _depth: 0) lg = "[#{dh[:type]}] status:#{dh[:status]}" lg += "\n MESSAGE: #{dh[:message]&.gsub(/\n/, "\n ")}" dh[:instance_variables]&.each do |var, val| lg += "\n #{var}: #{val}" end if (bt = dh[:backtrace] || []) lg += "\n BACKTRACE:\n " lg += bt.join("\n ") end if dh[:cause].is_a?(Hash) lg += "\n CAUSE: " lg += to_inspection_s(options: , _dh: dh[:cause]).strip.gsub(/\n/, "\n ") elsif dh[:cause].is_a?(String) lg += dh[:cause] end lg << "\n" end |
#to_json(options = {}) ⇒ Object
244 245 246 |
# File 'lib/coaster/core_ext/standard_error.rb', line 244 def to_json( = {}) Oj.dump(to_hash.with_indifferent_access, mode: :compat) end |
#user_message ⇒ Object
user friendly message, for overid
213 214 215 216 217 218 219 |
# File 'lib/coaster/core_ext/standard_error.rb', line 213 def return _translate if description.present? || tkey.present? return "#{_translate} (#{user_digests})" unless defined?(@coaster) rescue => e "#{} (user_message_error - #{e.class.name} #{e.})" end |