Class: Lookout::Exception::Backtrace

Inherits:
Object
  • Object
show all
Defined in:
lib/lookout-3.0/exception/backtrace.rb

Overview

Provides non-failing access to an exception backtrace. The backtrace entries are Lookout::Encoded for output and the backtrace may be filtered to not include entries from inside Lookout.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(backtrace, trim, filter = ENV['LOOKOUT_DO_NOT_FILTER_BACKTRACE'].nil?) ⇒ Backtrace

Returns a new instance of Backtrace.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/lookout-3.0/exception/backtrace.rb', line 24

def initialize(backtrace, trim, filter = ENV['LOOKOUT_DO_NOT_FILTER_BACKTRACE'].nil?)
  super(if nil == backtrace
          []
        elsif String === backtrace or Array === backtrace
          (String === backtrace ? [backtrace] : backtrace).map{ |line|
            begin
              Lookout::Encode.new(line).call
            rescue => e
              '(cannot retrieve backtrace entry: %s)' %
                Lookout::Exception.new(e)
            end
          }
        else
          ['(backtrace is not an Array of String: %s)' %
           Lookout::Inspect.new(backtrace, 'backtrace')]
        end, trim, filter)
end

Class Method Details

.from(exception) ⇒ Backtrace

Returns A backtrace wrapper of EXCEPTION’s backtrace, trimmed if EXCEPTION is a SystemStackError, and empty if the backtrace can’t be retrieved.

Parameters:

Returns:

  • (Backtrace)

    A backtrace wrapper of EXCEPTION’s backtrace, trimmed if EXCEPTION is a SystemStackError, and empty if the backtrace can’t be retrieved



12
13
14
15
# File 'lib/lookout-3.0/exception/backtrace.rb', line 12

def from(exception)
  new(nil == exception ? nil : (exception.backtrace rescue nil),
      SystemStackError === exception)
end

Instance Method Details

#to_sObject

Returns The concatenation of the backtrace entries.

Returns:

  • The concatenation of the backtrace entries



43
44
45
# File 'lib/lookout-3.0/exception/backtrace.rb', line 43

def to_s
  trimmed(filtered.map{ |location| ["\tfrom ", location].join('') }).join("\n")
end