Sha256: e017a3a93113d6df898863b9f3f317900fb769d38bc628df61c5fe7cc4bea65b

Contents?: true

Size: 1.43 KB

Versions: 24

Compression:

Stored size: 1.43 KB

Contents

# frozen_string_literal: true

require "set"

module Sentry
  class ExceptionInterface < Interface
    # @return [<Array[SingleExceptionInterface]>]
    attr_reader :values

    # @param exceptions [Array<SingleExceptionInterface>]
    def initialize(exceptions:)
      @values = exceptions
    end

    # @return [Hash]
    def to_hash
      data = super
      data[:values] = data[:values].map(&:to_hash) if data[:values]
      data
    end

    # Builds ExceptionInterface with given exception and stacktrace_builder.
    # @param exception [Exception]
    # @param stacktrace_builder [StacktraceBuilder]
    # @see SingleExceptionInterface#build_with_stacktrace
    # @see SingleExceptionInterface#initialize
    # @param mechanism [Mechanism]
    # @return [ExceptionInterface]
    def self.build(exception:, stacktrace_builder:, mechanism:)
      exceptions = Sentry::Utils::ExceptionCauseChain.exception_to_array(exception).reverse
      processed_backtrace_ids = Set.new

      exceptions = exceptions.map do |e|
        if e.backtrace && !processed_backtrace_ids.include?(e.backtrace.object_id)
          processed_backtrace_ids << e.backtrace.object_id
          SingleExceptionInterface.build_with_stacktrace(exception: e, stacktrace_builder: stacktrace_builder, mechanism: mechanism)
        else
          SingleExceptionInterface.new(exception: exception, mechanism: mechanism)
        end
      end

      new(exceptions: exceptions)
    end
  end
end

Version data entries

24 entries across 24 versions & 2 rubygems

Version Path
sentry-ruby-core-5.22.2 lib/sentry/interfaces/exception.rb
sentry-ruby-5.22.2 lib/sentry/interfaces/exception.rb
sentry-ruby-core-5.22.1 lib/sentry/interfaces/exception.rb
sentry-ruby-5.22.1 lib/sentry/interfaces/exception.rb
sentry-ruby-5.22.0 lib/sentry/interfaces/exception.rb
sentry-ruby-core-5.22.0 lib/sentry/interfaces/exception.rb
sentry-ruby-5.21.0 lib/sentry/interfaces/exception.rb
sentry-ruby-core-5.21.0 lib/sentry/interfaces/exception.rb
sentry-ruby-5.20.1 lib/sentry/interfaces/exception.rb
sentry-ruby-core-5.20.1 lib/sentry/interfaces/exception.rb
sentry-ruby-5.20.0 lib/sentry/interfaces/exception.rb
sentry-ruby-core-5.20.0 lib/sentry/interfaces/exception.rb
sentry-ruby-core-5.19.0 lib/sentry/interfaces/exception.rb
sentry-ruby-5.19.0 lib/sentry/interfaces/exception.rb
sentry-ruby-core-5.18.2 lib/sentry/interfaces/exception.rb
sentry-ruby-5.18.2 lib/sentry/interfaces/exception.rb
sentry-ruby-core-5.18.1 lib/sentry/interfaces/exception.rb
sentry-ruby-5.18.1 lib/sentry/interfaces/exception.rb
sentry-ruby-5.18.0 lib/sentry/interfaces/exception.rb
sentry-ruby-core-5.18.0 lib/sentry/interfaces/exception.rb