Exception: StandardError
- Defined in:
- lib/coaster/core_ext/standard_error.rb,
lib/coaster/core_ext/standard_error/raven.rb
Instance Attribute Summary collapse
-
#level ⇒ Object
Returns the value of attribute level.
-
#raven ⇒ Object
Returns the value of attribute raven.
-
#tags ⇒ Object
Returns the value of attribute tags.
-
#tkey ⇒ Object
Returns the value of attribute tkey.
Class Method Summary collapse
Instance Method Summary collapse
- #attributes ⇒ Object (also: #attr)
- #capture(options = {}) ⇒ Object
- #description ⇒ Object (also: #desc)
- #http_status ⇒ Object
-
#initialize(message = nil, cause = $!) ⇒ StandardError
constructor
A new instance of StandardError.
-
#initialize_original ⇒ StandardError
A new instance of StandardError.
- #just_logging ⇒ Object
- #logging(options = {}) ⇒ Object
- #object ⇒ Object (also: #obj)
- #status ⇒ Object
- #to_detail ⇒ Object
- #to_hash ⇒ Object
- #to_json ⇒ Object
- #translate_params ⇒ Object
Constructor Details
#initialize(message = nil, cause = $!) ⇒ StandardError
Returns a new instance of StandardError.
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 |
# File 'lib/coaster/core_ext/standard_error.rb', line 20 def initialize( = nil, cause = $!) @tags = [] @level = 'error' @attributes = HashWithIndifferentAccess.new @tkey = nil case when Exception msg = set_backtrace(.backtrace) when StandardError @tags = . @level = .level @tkey = .tkey @attributes = .attributes msg = set_backtrace(.backtrace) when Hash then hash = .with_indifferent_access rescue msg = hash[:message] msg = hash[:msg] if msg.nil? msg = hash[:m] if msg.nil? @tags = Array(hash.delete(:tags) || hash.delete(:tag)) @level = hash.delete(:level) || hash.delete(:severity) || @level @tkey = hash.delete(:tkey) msg = cause. if msg.nil? && cause @attributes.merge!(hash) when String, NilClass then msg = when FalseClass then msg = false else msg = @attributes[:object] = end msg = nil if msg == false super(msg) set_backtrace(cause.backtrace) if cause end |
Instance Attribute Details
#level ⇒ Object
Returns the value of attribute level.
18 19 20 |
# File 'lib/coaster/core_ext/standard_error.rb', line 18 def level @level end |
#raven ⇒ Object
Returns the value of attribute raven.
2 3 4 |
# File 'lib/coaster/core_ext/standard_error/raven.rb', line 2 def raven @raven end |
#tags ⇒ Object
Returns the value of attribute tags.
18 19 20 |
# File 'lib/coaster/core_ext/standard_error.rb', line 18 def @tags end |
#tkey ⇒ Object
Returns the value of attribute tkey.
18 19 20 |
# File 'lib/coaster/core_ext/standard_error.rb', line 18 def tkey @tkey end |
Class Method Details
.http_status ⇒ Object
13 14 15 |
# File 'lib/coaster/core_ext/standard_error.rb', line 13 def http_status 500 end |
.status ⇒ Object
9 10 11 |
# File 'lib/coaster/core_ext/standard_error.rb', line 9 def status 999999 # Unknown end |
Instance Method Details
#attributes ⇒ Object Also known as: attr
65 66 67 68 69 70 71 |
# File 'lib/coaster/core_ext/standard_error.rb', line 65 def attributes if cause && cause.respond_to?(:attributes) cause.attributes.merge(@attributes) else @attributes end end |
#capture(options = {}) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/coaster/core_ext/standard_error/raven.rb', line 10 def capture( = {}) notes = raven.merge( || {}) self. += Array(notes[:fingerprint]) notes[:fingerprint] = self. notes[:level] ||= self.level notes[:extra] = (notes[:extra] || {}).merge(attributes) Raven.annotate_exception(self, notes) Raven.capture_exception(self) rescue => e msg = "#{e.class.name}: #{e.}" msg += "\n\t" + e.backtrace.join("\n\t") Raven.logger.error(msg) end |
#description ⇒ Object Also known as: desc
78 79 80 |
# File 'lib/coaster/core_ext/standard_error.rb', line 78 def description attributes[:description] || attributes[:desc] || end |
#http_status ⇒ Object
74 75 76 |
# File 'lib/coaster/core_ext/standard_error.rb', line 74 def http_status attributes[:http_status] || self.class.http_status 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 |
# File 'lib/coaster/core_ext/standard_error/raven.rb', line 4 def initialize( = nil, cause = $!) @tags = [] @level = 'error' @attributes = HashWithIndifferentAccess.new @tkey = nil case when Exception msg = set_backtrace(.backtrace) when StandardError @tags = . @level = .level @tkey = .tkey @attributes = .attributes msg = set_backtrace(.backtrace) when Hash then hash = .with_indifferent_access rescue msg = hash[:message] msg = hash[:msg] if msg.nil? msg = hash[:m] if msg.nil? @tags = Array(hash.delete(:tags) || hash.delete(:tag)) @level = hash.delete(:level) || hash.delete(:severity) || @level @tkey = hash.delete(:tkey) msg = cause. if msg.nil? && cause @attributes.merge!(hash) when String, NilClass then msg = when FalseClass then msg = false else msg = @attributes[:object] = end msg = nil if msg == false super(msg) set_backtrace(cause.backtrace) if cause end |
#just_logging ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/coaster/core_ext/standard_error/raven.rb', line 26 def logging( = {}) logger = [:logger] logger = Rails.logger if logger.nil? && defined?(Rails) return nil unless logger cl = [:cleaner] || cleaner msg = to_detail if cl && backtrace msg += "\t\t" msg += cleaner.clean(backtrace).join("\n\t\t") end logger.tagged(*) do if logger.respond_to?(level) logger.send(level, msg) else logger.error(msg) end end end |
#logging(options = {}) ⇒ Object
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 133 def logging( = {}) logger = [:logger] logger = Rails.logger if logger.nil? && defined?(Rails) return nil unless logger cl = [:cleaner] || cleaner msg = to_detail if cl && backtrace msg += "\t\t" msg += cleaner.clean(backtrace).join("\n\t\t") end logger.tagged(*) do if logger.respond_to?(level) logger.send(level, msg) else logger.error(msg) end end end |
#object ⇒ Object Also known as: obj
83 84 85 |
# File 'lib/coaster/core_ext/standard_error.rb', line 83 def object attributes[:object] || attributes[:obj] end |
#status ⇒ Object
61 62 63 |
# File 'lib/coaster/core_ext/standard_error.rb', line 61 def status self.class.status end |
#to_detail ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/coaster/core_ext/standard_error.rb', line 114 def to_detail lg = "[#{self.class.name}] status:#{status}" lg += "\n\tMESSAGE: #{.gsub(/\n/, "\n\t\t")}" instance_variables.each do |var| unless var.to_s.start_with?('@_') lg += "\n\t#{var}: #{instance_variable_get(var).inspect}" end end if cause if cause.respond_to?(:to_detail) lg += "\n\tCAUSE: " lg += cause.to_detail.strip.gsub(/\n/, "\n\t") else lg += "\n\tCAUSE: #{cause.class.name}: #{cause..gsub(/\n/, "\n\t\t")}" end end lg << "\n" end |
#to_hash ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/coaster/core_ext/standard_error.rb', line 88 def to_hash hash = @attributes.merge( type: self.class.name, status: status, http_status: http_status, message: ) if cause if cause.respond_to?(:to_hash) hash[:cause] = cause.to_hash else hash[:cause] = cause end end hash end |
#to_json ⇒ Object
110 111 112 |
# File 'lib/coaster/core_ext/standard_error.rb', line 110 def to_json Oj.dump(to_hash.with_indifferent_access, mode: :compat) end |
#translate_params ⇒ Object
103 104 105 106 107 108 |
# File 'lib/coaster/core_ext/standard_error.rb', line 103 def translate_params attributes.merge( type: self.class.name, status: status, http_status: http_status, message: ) end |