Module: Umlaut::Util

Defined in:
lib/umlaut/util.rb

Class Method Summary collapse

Class Method Details

.clean_backtrace(exception) ⇒ Object

Provide a prettified and cleaned exception backtrace array from an exception, using the Rails backtrace cleaner, as configured in the app. Umlaut configures it, in an initializer declared in umlaut.rb, to prettify and include Umlaut trace lines.

This will produce a stack trace similar to what Rails logs by default for uncaught exceptions. We use it for exception logging in several places.

Pass in the exception itself, not `exception.backtrace`.


14
15
16
17
18
19
20
21
22
# File 'lib/umlaut/util.rb', line 14

def clean_backtrace(exception)
  if defined?(Rails) && Rails.respond_to?(:backtrace_cleaner)
    trace = Rails.backtrace_cleaner.clean(exception.backtrace)
    trace = Rails.backtrace_cleaner.clean(exception.backtrace, :all) if trace.empty?
    return trace
  else
    return exception.backtrace
  end
end