Sha256: 8c4b2f90dac986d0346169f2721b94e6600566f584fb4721482dca1509cfc26d

Contents?: true

Size: 1.06 KB

Versions: 1

Compression:

Stored size: 1.06 KB

Contents

# frozen_string_literal: true

module ElasticAPM
  class Error
    # @api private
    class Exception
      MOD_SPLIT = '::'

      def initialize(attrs = nil)
        return unless attrs

        attrs.each do |key, val|
          send(:"#{key}=", val)
        end
      end

      def self.from_exception(exception, **attrs)
        new({
          message: exception.message.to_s,
          type: exception.class.to_s,
          module: format_module(exception),
          cause: exception.cause && Exception.from_exception(exception.cause)
        }.merge(attrs))
      end

      attr_accessor(
        :attributes,
        :code,
        :handled,
        :message,
        :module,
        :stacktrace,
        :type,
        :cause
      )

      def inspect
        "<ElasticAPM::Error::Exception" \
          " type:#{type}" \
          " message:#{message}" \
          ">"
      end

      class << self
        private

        def format_module(exception)
          exception.class.to_s.split(MOD_SPLIT)[0...-1].join(MOD_SPLIT)
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
elastic-apm-3.2.0 lib/elastic_apm/error/exception.rb