Class: Statsig::ErrorBoundary

Inherits:
Object
  • Object
show all
Defined in:
lib/error_boundary.rb

Instance Method Summary collapse

Constructor Details

#initialize(sdk_key) ⇒ ErrorBoundary

Returns a new instance of ErrorBoundary.



8
9
10
11
# File 'lib/error_boundary.rb', line 8

def initialize(sdk_key)
  @sdk_key = sdk_key
  @seen = Set.new
end

Instance Method Details

#capture(recover: -> {}, caller: nil) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/error_boundary.rb', line 13

def capture(recover: -> {}, caller: nil)
  begin
    res = yield
  rescue StandardError, SystemStackError => e
    if e.is_a?(Statsig::UninitializedError) || e.is_a?(Statsig::ValueError)
      raise e
    end

    puts '[Statsig]: An unexpected exception occurred.'
    puts e.message
    log_exception(e, tag: caller&.to_s)
    res = recover.call
  end
  return res
end