class BarsoomUtils::ExceptionNotifier

Public Class Methods

message(message, details_or_context = nil, context_or_nothing = nil) click to toggle source
# File lib/barsoom_utils/exception_notifier.rb, line 17
def self.message(message, details_or_context = nil, context_or_nothing = nil)
  if context_or_nothing
    details = details_or_context
    context = context_or_nothing
  elsif details_or_context.is_a?(Hash)
    details = nil
    context = details_or_context
  else
    details = details_or_context
    context = {}
  end

  details ||= "(no message)"

  Honeybadger.notify(
    error_class: message,
    error_message: details.to_s,
    context: context.to_h,
  )
end
notify(exception, context: {}) click to toggle source
# File lib/barsoom_utils/exception_notifier.rb, line 7
def self.notify(exception, context: {})
  # Inelegant workaround for the fact that we've confused this method with .message at least once.
  # TODO: Fold them into a single method?
  unless exception.is_a?(Exception)
    raise "Expected an exception but got: #{exception.inspect}"
  end

  Honeybadger.notify(exception, context: context)
end
run_with_context(context, &block) click to toggle source

Wrap this around code to add context when reporting errors.

# File lib/barsoom_utils/exception_notifier.rb, line 39
def self.run_with_context(context, &block)
  # The load/dump achieves a "deep dup" without the "deep dep" of Active Support 🥁
  old_context = Marshal.load(Marshal.dump(Honeybadger.get_context))

  Honeybadger.context(context)
  block.call
ensure
  Honeybadger.context.clear!
  Honeybadger.context(old_context)
end