Class: Statsig::ErrorBoundary

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/error_boundary.rb

Instance Method Summary collapse

Constructor Details

#initialize(sdk_key) ⇒ ErrorBoundary

Returns a new instance of ErrorBoundary.



13
14
15
16
# File 'lib/error_boundary.rb', line 13

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

Instance Method Details

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



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/error_boundary.rb', line 18

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

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