Skip to content

Commit

Permalink
Merge pull request #278 from eagletmt/relative-path
Browse files Browse the repository at this point in the history
Truncate project_root prefix from filename
  • Loading branch information
nateberkopec committed Jan 22, 2015
2 parents dfb5930 + 40402af commit 6ed265c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 6 additions & 0 deletions lib/raven/interfaces/stack_trace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ def filename
return nil if self.abs_path.nil?

prefix = $LOAD_PATH.select { |s| self.abs_path.start_with?(s.to_s) }.sort_by { |s| s.to_s.length }.last
if prefix.nil? && Raven.configuration.project_root
project_root = Raven.configuration.project_root.to_s
if self.abs_path.start_with?(project_root)
prefix = project_root
end
end
prefix ? self.abs_path[prefix.to_s.chomp(File::SEPARATOR).length+1..-1] : self.abs_path
end

Expand Down
4 changes: 2 additions & 2 deletions spec/raven/event_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -401,11 +401,11 @@ class SubExc < BaseExc; end
expect(frames[1][:in_app]).to eq(false)
expect(frames[2][:filename]).to eq("/gem/lib/path")
expect(frames[2][:in_app]).to eq(false)
expect(frames[3][:filename]).to eq("/rails/root/app/foobar")
expect(frames[3][:filename]).to eq("app/foobar")
expect(frames[3][:in_app]).to eq(true)
expect(frames[4][:filename]).to eq("vendor/bundle/some_gem.rb")
expect(frames[4][:in_app]).to eq(false)
expect(frames[5][:filename]).to eq("/rails/root/vendor/bundle/cache/other_gem.rb")
expect(frames[5][:filename]).to eq("vendor/bundle/cache/other_gem.rb")
expect(frames[5][:in_app]).to eq(false)
end
end
Expand Down

0 comments on commit 6ed265c

Please sign in to comment.