Class: Failbot::ExceptionFormat::Structured

Inherits:
Object
  • Object
show all
Defined in:
lib/failbot/exception_format/structured.rb

Overview

A newer exception format , based on the one sentry uses. Aside from different names and locations for things, the notable difference from haystack is that backtrace data has more structure.

Constant Summary collapse

EMPTY_ARRAY =
[].freeze

Class Method Summary collapse

Class Method Details

.call(e) ⇒ Object

Format an exception.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/failbot/exception_format/structured.rb', line 14

def self.call(e)
  message = e.message.to_s
  class_name = e.class.to_s
  stacktrace = begin
    Failbot.backtrace_parser.call(e)
  rescue => ex
    message += "\nUnable to parse backtrace (#{ex.inspect})\nDon't put non-backtrace text in Exception#backtrace please!\nSo-called backtrace follows:\n#{e.backtrace.join("\n")}"
    class_name += " (backtrace failed to parse)"
    EMPTY_ARRAY
  end
  {
    "exception_detail" => [ # TODO Once supported in failbotg, this should be an array of
      {                     # hashes generated from subsequent calls to Exception#cause.
        "type" => class_name,
        "value" => message,
        "stacktrace" => stacktrace
      }
    ],
    "ruby" => RUBY_DESCRIPTION,
    "created_at" => Time.now.utc.iso8601(6)
  }
end

.exception_classname_from_hash(hash) ⇒ Object

given a hash generated by this class, return the exception class name.



43
44
45
# File 'lib/failbot/exception_format/structured.rb', line 43

def self.exception_classname_from_hash(hash)
  hash.dig("exception_detail", 0, "type")
end

.exception_message_from_hash(hash) ⇒ Object

given a hash generated by this class, return the exception message.



38
39
40
# File 'lib/failbot/exception_format/structured.rb', line 38

def self.exception_message_from_hash(hash)
  hash.dig("exception_detail", 0, "value")
end