Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions lib/raven/backtrace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ class Backtrace
class Line

# regexp (optionnally allowing leading X: for windows support)
INPUT_FORMAT = %r{^((?:[a-zA-Z]:)?[^:]+|<.*>):(\d+)(?::in `([^']+)')?$}.freeze
RUBY_INPUT_FORMAT = %r{^((?:[a-zA-Z]:)?[^:]+|<.*>):(\d+)(?::in `([^']+)')?$}.freeze

# org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:170)
JAVA_INPUT_FORMAT = %r{^(.+)\.([^\.]+)\(([^\:]+)\:(\d+)\)$}.freeze

APP_DIRS_PATTERN = /(bin|app|config|lib|test)/

Expand All @@ -22,16 +25,27 @@ class Line
# The method of the line (such as index)
attr_reader :method

# The module name (JRuby)
attr_reader :module_name

# Parses a single line of a given backtrace
# @param [String] unparsed_line The raw line from +caller+ or some backtrace
# @return [Line] The parsed backtrace line
def self.parse(unparsed_line)
_, file, number, method = unparsed_line.match(INPUT_FORMAT).to_a
new(file, number, method)
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

def initialize(file, number, method)
def initialize(file, number, method, module_name)
self.file = file
self.module_name = module_name
self.number = number.to_i
self.method = method
end
Expand Down Expand Up @@ -66,7 +80,7 @@ def inspect

private

attr_writer :file, :number, :method
attr_writer :file, :number, :method, :module_name
end

# holder for an Array of Backtrace::Line instances
Expand Down
5 changes: 3 additions & 2 deletions lib/raven/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,11 @@ def self.stacktrace_interface_from(int, evt, backtrace)
backtrace = Backtrace.parse(backtrace)
int.frames = backtrace.lines.reverse.map do |line|
StacktraceInterface::Frame.new.tap do |frame|
frame.abs_path = line.file
frame.function = line.method
frame.abs_path = line.file if line.file
frame.function = line.method if line.method
frame.lineno = line.number
frame.in_app = line.in_app
frame.module = line.module_name if line.module_name

if evt.configuration[:context_lines] && frame.abs_path
frame.pre_context, frame.context_line, frame.post_context = \
Expand Down
1 change: 1 addition & 0 deletions lib/raven/interfaces/stack_trace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class Frame < Interface
attr_accessor :pre_context
attr_accessor :post_context
attr_accessor :context_line
attr_accessor :module
attr_accessor :lineno
attr_accessor :in_app

Expand Down
17 changes: 17 additions & 0 deletions spec/raven/event_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,23 @@ class SubExc < BaseExc; end
end
end

if RUBY_PLATFORM == "java"
context 'when running under jRuby' do
let(:exception) do
begin
raise java.lang.OutOfMemoryError.new("A Java error")
rescue Exception => e
return e
end
end

it 'should have a backtrace' do
frames = hash[:exception][:values][0][:stacktrace][:frames]
expect(frames.length).not_to eq(0)
end
end
end

context 'when the exception has a backtrace' do
let(:exception) do
e = Exception.new(message)
Expand Down