Class: Raven::Backtrace::Line

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

Overview

Handles backtrace parsing line by line

Constant Summary collapse

RUBY_INPUT_FORMAT =

regexp (optionnally allowing leading X: for windows support)

%r{^((?:[a-zA-Z]:)?[^:]+|<.*>):(\d+)(?::in `([^']+)')?$}
JAVA_INPUT_FORMAT =

org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:170)

%r{^(.+)\.([^\.]+)\(([^\:]+)\:(\d+)\)$}
APP_DIRS_PATTERN =
/(bin|exe|app|config|lib|test)/

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file, number, method, module_name) ⇒ Line

Returns a new instance of Line.



44
45
46
47
48
49
# File 'lib/raven/backtrace.rb', line 44

def initialize(file, number, method, module_name)
  self.file = file
  self.module_name = module_name
  self.number = number.to_i
  self.method = method
end

Instance Attribute Details

#fileObject

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



18
19
20
# File 'lib/raven/backtrace.rb', line 18

def file
  @file
end

#methodObject

The method of the line (such as index)



24
25
26
# File 'lib/raven/backtrace.rb', line 24

def method
  @method
end

#module_nameObject

The module name (JRuby)



27
28
29
# File 'lib/raven/backtrace.rb', line 27

def module_name
  @module_name
end

#numberObject

The line number portion of the line



21
22
23
# File 'lib/raven/backtrace.rb', line 21

def number
  @number
end

Class Method Details

.parse(unparsed_line) ⇒ Line

Parses a single line of a given backtrace

Parameters:

  • unparsed_line (String)

    The raw line from caller or some backtrace

Returns:

  • (Line)

    The parsed backtrace line



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/raven/backtrace.rb', line 32

def self.parse(unparsed_line)
  ruby_match = unparsed_line.match(RUBY_INPUT_FORMAT)
  if ruby_match
    _, file, number, method = ruby_match.to_a
    module_name = nil
  else
    java_match = unparsed_line.match(JAVA_INPUT_FORMAT)
    _, module_name, method, file, number = java_match.to_a
  end
  new(file, number, method, module_name)
end

Instance Method Details

#==(other) ⇒ Object



71
72
73
# File 'lib/raven/backtrace.rb', line 71

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

#in_appObject



51
52
53
54
55
56
57
58
59
60
# File 'lib/raven/backtrace.rb', line 51

def in_app
  app_dirs = Raven.configuration.app_dirs_pattern || APP_DIRS_PATTERN
  @in_app_pattern ||= Regexp.new("^(#{project_root}/)?#{app_dirs}")

  if self.file =~ @in_app_pattern
    true
  else
    false
  end
end

#inspectObject



75
76
77
# File 'lib/raven/backtrace.rb', line 75

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

#project_rootObject



62
63
64
# File 'lib/raven/backtrace.rb', line 62

def project_root
  @project_root ||= Raven.configuration.project_root && Raven.configuration.project_root.to_s
end

#to_sObject

Reconstructs the line in a readable fashion



67
68
69
# File 'lib/raven/backtrace.rb', line 67

def to_s
  "#{file}:#{number}:in `#{method}'"
end