Skip to content
Merged
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
1 change: 1 addition & 0 deletions lib/raven/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ def self._source_lines(_path, _from, _to)
end

def get_file_context(filename, lineno, context)
return nil, nil, nil unless Raven::LineCache.is_valid_file(filename)
lines = (2 * context + 1).times.map do |i|
Raven::LineCache.getline(filename, lineno - context + i)
end
Expand Down
11 changes: 9 additions & 2 deletions lib/raven/linecache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,24 @@ class LineCache
class << self
CACHE = {}

def is_valid_file(path)
lines = getlines(path)
return lines != nil
end

def getlines(path)
CACHE[path] ||= begin
IO.readlines(path)
rescue
[]
nil
end
end

def getline(path, n)
return nil if n < 1
getlines(path)[n - 1]
lines = getlines(path)
return nil if lines == nil
lines[n - 1]
end
end
end
Expand Down