module Robustly::Methods

Public Instance Methods

robustly(options = {})
Alias for: safely
safely(options = {}) { || ... } click to toggle source
# File lib/robustly.rb, line 25
def safely(options = {})
  yield
rescue *Array(options[:only] || StandardError) => e
  raise e if Array(options[:except]).any? { |c| e.is_a?(c) }
  raise e if Robustly.raise_envs.include?(Robustly.env)
  sample = options[:sample] || options[:throttle]
  if sample ? rand < 1.0 / sample : true
    begin
      Robustly.report_exception(e) unless Array(options[:silence]).any? { |c| e.is_a?(c) }
    rescue => e2
      $stderr.puts "FAIL-SAFE #{e2.class.name}: #{e2.message}"
    end
  end
  options[:default]
end
Also aliased as: yolo, robustly
yolo(options = {})
Alias for: safely