Class: Honeybadger::Backtrace::Line Private

Inherits:
Object
  • Object
show all
Defined in:
lib/honeybadger/backtrace.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Handles backtrace parsing line by line.

Constant Summary collapse

INPUT_FORMAT =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Backtrace line regexp (optionally allowing leading X: for windows support).

%r{^((?:[a-zA-Z]:)?[^:]+):(\d+)(?::in `([^']+)')?$}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file, number, method, filtered_file = file, filtered_number = number, filtered_method = method, source_radius = 2) ⇒ Line

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Line


52
53
54
55
56
57
58
59
60
61
62
# File 'lib/honeybadger/backtrace.rb', line 52

def initialize(file, number, method, filtered_file = file,
               filtered_number = number, filtered_method = method,
               source_radius = 2)
  self.filtered_file   = filtered_file
  self.filtered_number = filtered_number
  self.filtered_method = filtered_method
  self.file            = file
  self.number          = number
  self.method          = method
  self.source_radius   = source_radius
end

Instance Attribute Details

#fileObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The file portion of the line (such as app/models/user.rb).


13
14
15
# File 'lib/honeybadger/backtrace.rb', line 13

def file
  @file
end

#filtered_fileObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Filtered representations


22
23
24
# File 'lib/honeybadger/backtrace.rb', line 22

def filtered_file
  @filtered_file
end

#filtered_methodObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Filtered representations


22
23
24
# File 'lib/honeybadger/backtrace.rb', line 22

def filtered_method
  @filtered_method
end

#filtered_numberObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Filtered representations


22
23
24
# File 'lib/honeybadger/backtrace.rb', line 22

def filtered_number
  @filtered_number
end

#methodObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The method of the line (such as index).


19
20
21
# File 'lib/honeybadger/backtrace.rb', line 19

def method
  @method
end

#numberObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The line number portion of the line.


16
17
18
# File 'lib/honeybadger/backtrace.rb', line 16

def number
  @number
end

Class Method Details

.parse(unparsed_line, opts = {}) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parses a single line of a given backtrace

Parameters:

  • unparsed_line (String)

    The raw line from caller or some backtrace.

Returns:

  • The parsed backtrace line.


29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/honeybadger/backtrace.rb', line 29

def self.parse(unparsed_line, opts = {})
  filters = opts[:filters] || []
  filtered_line = filters.reduce(unparsed_line) do |line, proc|
    # TODO: Break if nil
    if proc.arity == 2
      proc.call(line, opts[:config])
    else
      proc.call(line)
    end
  end

  if filtered_line
    match = unparsed_line.match(INPUT_FORMAT) || [].freeze
    fmatch = filtered_line.match(INPUT_FORMAT) || [].freeze

    file, number, method = match[1], match[2], match[3]
    filtered_args = [fmatch[1], fmatch[2], fmatch[3]]
    new(file, number, method, *filtered_args, opts.fetch(:source_radius, 2))
  else
    nil
  end
end

Instance Method Details

#==(other) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


69
70
71
# File 'lib/honeybadger/backtrace.rb', line 69

def ==(other)
  to_s == other.to_s
end

#application?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Determines if this line is part of the application trace or not.

Returns:

  • (Boolean)

78
79
80
# File 'lib/honeybadger/backtrace.rb', line 78

def application?
  (filtered_file =~ /^\[PROJECT_ROOT\]/i) && !(filtered_file =~ /^\[PROJECT_ROOT\]\/vendor/i)
end

#inspectObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


73
74
75
# File 'lib/honeybadger/backtrace.rb', line 73

def inspect
  "<Line:#{to_s}>"
end

#sourceObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


82
83
84
# File 'lib/honeybadger/backtrace.rb', line 82

def source
  @source ||= get_source(file, number, source_radius)
end

#to_sObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Reconstructs the line in a readable fashion.


65
66
67
# File 'lib/honeybadger/backtrace.rb', line 65

def to_s
  "#{filtered_file}:#{filtered_number}:in `#{filtered_method}'"
end