# Copyright (c) 2022 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details. # frozen_string_literal: true require_relative 'telemetry_exception_base' require_relative 'telemetry_exception_stack_frame' module Contrast module Agent module Telemetry module TelemetryException # This class will hold the all the information for the specific exception # and will be passed in the Exception message itself class MessageException < Contrast::Agent::Telemetry::TelemetryException::Base 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::TelemetryException::StackFrame } }.cs__freeze # @return [String] The type of the exception itself attr_reader :type # stack frames for the message exception # @return [Array] attr_reader :stack_frames # @return [String] attr_reader :module_name # @return [String] attr_reader :value def initialize type, stack_frame super() @type = type @stack_frames = Array.new(1, stack_frame) validate(VALIDATIONS) end # @param stack_frame [Contrast::Agent::Telemetry::TelemetryException::StackFrame] def push stack_frame validate_class(stack_frame, Contrast::Agent::Telemetry::TelemetryException::StackFrame, 'stack_frame') @stack_frames << stack_frame end def module_name= module_name @module_name = module_name validate_field(VALIDATIONS[:module_name], 'module_name') end def value= value @value = value validate_field(VALIDATIONS[:value], 'value') end def to_controlled_hash super { type: type, module: module_name, stackFrames: stack_frames.map(&:to_controlled_hash), value: value }.compact end class << self def build type, value, module_name, stackframes inst = new(type, stackframes) inst.module_name = module_name if module_name inst.value = value inst end end end end end end end