-
-
Notifications
You must be signed in to change notification settings - Fork 479
/
exception.rb
45 lines (38 loc) · 1.43 KB
/
exception.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# 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