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). Capture quoted strings either with leading backtick (pre Ruby 3.4) or single quote.

%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.



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

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).



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

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



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

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



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

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



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

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).



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

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.



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

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.



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

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.



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

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)


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

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.



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

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.



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

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.



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

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