Module: Tracee::Extensions::Exception

Defined in:
lib/tracee/ext/exception.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.prepended(exc_class) ⇒ Object



5
6
7
# File 'lib/tracee/ext/exception.rb', line 5

def self.prepended(exc_class)
  exc_class.send :class_attribute, :trace_decorator
end

Instance Method Details

#backtrace_with_cause_backtraceObject



70
71
72
# File 'lib/tracee/ext/exception.rb', line 70

def backtrace_with_cause_backtrace
  backtrace + (cause ? ["+ cause (#{cause.class}) backtrace", *cause.backtrace_with_cause_backtrace] : [])
end

#logObject

Use case: We have some method that we don’t want to crash application in production but want to have this crash potential been logged

def unsured_method

... some crashable calls ...

rescue PotentialException

$!.log

end



63
64
65
66
67
68
# File 'lib/tracee/ext/exception.rb', line 63

def log
  Rails.logger.error [
        "The exception has been handled: #{self.class} — #{message.force_encoding('UTF-8')}:",
        *Rails.backtrace_cleaner.clean(backtrace_with_cause_backtrace)
      ]*"\n"
end

#set_backtrace(trace) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/tracee/ext/exception.rb', line 29

def set_backtrace(trace)
  if decorator = self.class.trace_decorator
    if trace.is_a? Thread::Backtrace
      return trace
    else
      trace = decorator.(trace)
    end
  end
  
  super(trace)
end