Class: Contrast::Agent::Telemetry::Exception::MessageException

Inherits:
Base
  • Object
show all
Defined in:
lib/contrast/agent/telemetry/exception/message_exception.rb

Overview

This class will hold the all the information for the specific exception and will be passed in the Exception message itself

Constant Summary collapse

VALIDATIONS =
{
    type: { required: true, range: 1..256 },
    module_name: { required: false, range: 1..256 },
    value: { required: false, range: 1..256 },
    stack_frames: {
        required: true,
        range: 1..128,
        class: Contrast::Agent::Telemetry::Exception::StackFrame
    }
}.cs__freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, stack_frame) ⇒ MessageException

Returns a new instance of MessageException.



38
39
40
41
42
43
# File 'lib/contrast/agent/telemetry/exception/message_exception.rb', line 38

def initialize type, stack_frame
  super()
  @type = type
  @stack_frames = Array.new(1, stack_frame)
  validate(VALIDATIONS)
end

Instance Attribute Details

#module_nameString

Returns:



33
34
35
# File 'lib/contrast/agent/telemetry/exception/message_exception.rb', line 33

def module_name
  @module_name
end

#stack_framesArray<Contrast::Agent::Telemetry::Exception::StackFrame> (readonly)

stack frames for the message exception



30
31
32
# File 'lib/contrast/agent/telemetry/exception/message_exception.rb', line 30

def stack_frames
  @stack_frames
end

#typeString (readonly)

Returns The type of the exception itself.

Returns:

  • (String)

    The type of the exception itself



26
27
28
# File 'lib/contrast/agent/telemetry/exception/message_exception.rb', line 26

def type
  @type
end

#valueString

Returns:



36
37
38
# File 'lib/contrast/agent/telemetry/exception/message_exception.rb', line 36

def value
  @value
end

Class Method Details

.build(type, value, module_name, stackframes) ⇒ Object



75
76
77
78
79
80
# File 'lib/contrast/agent/telemetry/exception/message_exception.rb', line 75

def build type, value, module_name, stackframes
  inst = new(type, stackframes)
  inst.module_name = module_name if module_name
  inst.value = value
  inst
end

Instance Method Details

#push(stack_frame) ⇒ Object



47
48
49
50
# File 'lib/contrast/agent/telemetry/exception/message_exception.rb', line 47

def push stack_frame
  validate_class(stack_frame, Contrast::Agent::Telemetry::Exception::StackFrame, 'stack_frame')
  @stack_frames << stack_frame
end

#to_controlled_hashObject



64
65
66
67
68
69
70
71
72
# File 'lib/contrast/agent/telemetry/exception/message_exception.rb', line 64

def to_controlled_hash
  super
  {
      type: type,
      module: module_name,
      stackFrames: stack_frames.map(&:to_controlled_hash),
      value: value
  }.compact
end