Class: Datadog::Core::Error

Inherits:
Object
  • Object
show all
Defined in:
lib/datadog/core/error.rb

Overview

Error is a value-object responsible for sanitizing/encapsulating error data

Constant Summary collapse

BlankError =
Error.new
ContainsMessage =
->(v) { v.respond_to?(:message) }

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type = nil, message = nil, backtrace = nil) ⇒ Error

Returns a new instance of Error.



88
89
90
91
92
93
94
# File 'lib/datadog/core/error.rb', line 88

def initialize(type = nil, message = nil, backtrace = nil)
  backtrace = Array(backtrace).join("\n") unless backtrace.is_a?(String)

  @type = Utils.utf8_encode(type)
  @message = Utils.utf8_encode(message)
  @backtrace = Utils.utf8_encode(backtrace)
end

Instance Attribute Details

#backtraceObject (readonly)

Returns the value of attribute backtrace.



9
10
11
# File 'lib/datadog/core/error.rb', line 9

def backtrace
  @backtrace
end

#messageObject (readonly)

Returns the value of attribute message.



9
10
11
# File 'lib/datadog/core/error.rb', line 9

def message
  @message
end

#typeObject (readonly)

Returns the value of attribute type.



9
10
11
# File 'lib/datadog/core/error.rb', line 9

def type
  @type
end

Class Method Details

.build_from(value) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/datadog/core/error.rb', line 12

def build_from(value)
  case value
  when Error then value
  when Array then new(*value)
  when Exception then new(value.class, value.message, full_backtrace(value))
  when ContainsMessage then new(value.class, value.message)
  when String then new(nil, value)
  else BlankError
  end
end