Commit 92cfd2a846c3bdaa79bf5debd0514134ccf31772

Authored by Marcin Ciunelis
1 parent ec205e86
Exists in master and in 1 other branch production

add BacktraceLine.in_app

app/helpers/notices_helper.rb
1 1 # encoding: utf-8
2 2 module NoticesHelper
3   - def in_app_backtrace_line?(line)
4   - !!(line['file'] =~ %r{^\[PROJECT_ROOT\]/(?!(vendor))})
5   - end
6   -
7 3 def notice_atom_summary(notice)
8 4 render "notices/atom_entry.html.haml", :notice => notice
9 5 end
10 6  
11 7 def link_to_source_file(app, line, &block)
12 8 text = capture_haml(&block)
13   - if in_app_backtrace_line?(line)
  9 + if line.in_app?
14 10 return link_to_github(app, line, text) if app.github_repo?
15 11 return link_to_bitbucket(app, line, text) if app.bitbucket_repo?
16 12 if app.issue_tracker && app.issue_tracker.respond_to?(:url_to_file)
... ... @@ -48,7 +44,7 @@ module NoticesHelper
48 44 def grouped_lines(lines)
49 45 line_groups = []
50 46 lines.each do |line|
51   - in_app = in_app_backtrace_line?(line)
  47 + in_app = line.in_app?
52 48 if line_groups.last && line_groups.last[0] == in_app
53 49 line_groups.last[1] << line
54 50 else
... ...
app/models/backtrace_line.rb
1 1 class BacktraceLine
2 2 include Mongoid::Document
  3 + IN_APP_REGEXP = %r{^\[PROJECT_ROOT\]\/(?!(vendor))}
3 4  
4 5 field :number, :type => Integer
5 6 field :file
... ... @@ -7,8 +8,18 @@ class BacktraceLine
7 8  
8 9 embedded_in :backtrace
9 10  
  11 + scope :in_app, where(:file => IN_APP_REGEXP)
  12 +
10 13 def fingerprint
11 14 [number, file, method].join
12 15 end
  16 +
  17 + def to_s
  18 + "#{file}:#{number}"
  19 + end
  20 +
  21 + def in_app?
  22 + !!(file =~ IN_APP_REGEXP)
  23 + end
13 24 end
14 25  
... ...
app/models/notice.rb
... ... @@ -91,9 +91,8 @@ class Notice
91 91 request['session'] || {}
92 92 end
93 93  
94   - # Backtrace containing only files from the app itself (ignore gems)
95   - def app_backtrace
96   - backtrace_lines.select { |l| l && l['file'] && l['file'].include?("[PROJECT_ROOT]") }
  94 + def in_app_backtrace_lines
  95 + backtrace_lines.in_app
97 96 end
98 97  
99 98 protected
... ...
app/views/mailer/err_notification.html.haml
... ... @@ -27,16 +27,15 @@
27 27 %p.heading WHERE:
28 28 %p.monospace
29 29 = @notice.where
30   - - if (app_backtrace = @notice.app_backtrace).any?
31   - - app_backtrace.map {|l| "#{l['file']}:#{l['number']}" }.each do |line|
32   - %p.backtrace= line
  30 + - @notice.in_app_backtrace_lines.each do |line|
  31 + %p.backtrace= line
33 32 %br
34 33 %p.heading URL:
35 34 %p.monospace
36 35 - if @notice.request['url'].present?
37 36 = link_to @notice.request['url'], @notice.request['url']
38 37 %p.heading BACKTRACE:
39   - - @notice.backtrace_lines.map {|l| l ? "#{l['file']}:#{l['number']}" : nil }.compact.each do |line|
  38 + - @notice.backtrace_lines.each do |line|
40 39 %p.backtrace= line
41 40 %br
42 41  
... ...
app/views/mailer/err_notification.text.erb
... ... @@ -14,7 +14,7 @@ WHERE:
14 14  
15 15 <%= @notice.where %>
16 16  
17   -<% @notice.app_backtrace.map {|l| "#{l['file']}:#{l['number']}" }.each do |line| %>
  17 +<% @notice.in_app_backtrace_lines.each do |line| %>
18 18 <%= line %>
19 19 <% end %>
20 20  
... ... @@ -26,7 +26,7 @@ URL:
26 26  
27 27 BACKTRACE:
28 28  
29   -<% @notice.backtrace_lines.map {|l| l ? "#{l['file']}:#{l['number']}" : nil }.compact.each do |line| %>
  29 +<% @notice.backtrace_lines.each do |line| %>
30 30 <%= line %>
31 31 <% end %>
32 32  
... ...
app/views/notices/_backtrace_line.html.haml
1 1 %tr{:class => defined?(row_class) ? row_class : nil}
2   - %td.line{:class => (in_app_backtrace_line?(line) ? 'in-app' : nil)}
  2 + %td.line{:class => line.in_app? && 'in-app' }
3 3 = link_to_source_file(@app, line) do
4 4 %span.path>= path_for_backtrace_line(line)
5 5 %span.file>= file_for_backtrace_line(line)
... ...