Commit 92cfd2a846c3bdaa79bf5debd0514134ccf31772
1 parent
ec205e86
Exists in
master
and in
1 other branch
add BacktraceLine.in_app
Showing
6 changed files
with
21 additions
and
16 deletions
Show diff stats
app/helpers/notices_helper.rb
1 | # encoding: utf-8 | 1 | # encoding: utf-8 |
2 | module NoticesHelper | 2 | module NoticesHelper |
3 | - def in_app_backtrace_line?(line) | ||
4 | - !!(line['file'] =~ %r{^\[PROJECT_ROOT\]/(?!(vendor))}) | ||
5 | - end | ||
6 | - | ||
7 | def notice_atom_summary(notice) | 3 | def notice_atom_summary(notice) |
8 | render "notices/atom_entry.html.haml", :notice => notice | 4 | render "notices/atom_entry.html.haml", :notice => notice |
9 | end | 5 | end |
10 | 6 | ||
11 | def link_to_source_file(app, line, &block) | 7 | def link_to_source_file(app, line, &block) |
12 | text = capture_haml(&block) | 8 | text = capture_haml(&block) |
13 | - if in_app_backtrace_line?(line) | 9 | + if line.in_app? |
14 | return link_to_github(app, line, text) if app.github_repo? | 10 | return link_to_github(app, line, text) if app.github_repo? |
15 | return link_to_bitbucket(app, line, text) if app.bitbucket_repo? | 11 | return link_to_bitbucket(app, line, text) if app.bitbucket_repo? |
16 | if app.issue_tracker && app.issue_tracker.respond_to?(:url_to_file) | 12 | if app.issue_tracker && app.issue_tracker.respond_to?(:url_to_file) |
@@ -48,7 +44,7 @@ module NoticesHelper | @@ -48,7 +44,7 @@ module NoticesHelper | ||
48 | def grouped_lines(lines) | 44 | def grouped_lines(lines) |
49 | line_groups = [] | 45 | line_groups = [] |
50 | lines.each do |line| | 46 | lines.each do |line| |
51 | - in_app = in_app_backtrace_line?(line) | 47 | + in_app = line.in_app? |
52 | if line_groups.last && line_groups.last[0] == in_app | 48 | if line_groups.last && line_groups.last[0] == in_app |
53 | line_groups.last[1] << line | 49 | line_groups.last[1] << line |
54 | else | 50 | else |
app/models/backtrace_line.rb
1 | class BacktraceLine | 1 | class BacktraceLine |
2 | include Mongoid::Document | 2 | include Mongoid::Document |
3 | + IN_APP_REGEXP = %r{^\[PROJECT_ROOT\]\/(?!(vendor))} | ||
3 | 4 | ||
4 | field :number, :type => Integer | 5 | field :number, :type => Integer |
5 | field :file | 6 | field :file |
@@ -7,8 +8,18 @@ class BacktraceLine | @@ -7,8 +8,18 @@ class BacktraceLine | ||
7 | 8 | ||
8 | embedded_in :backtrace | 9 | embedded_in :backtrace |
9 | 10 | ||
11 | + scope :in_app, where(:file => IN_APP_REGEXP) | ||
12 | + | ||
10 | def fingerprint | 13 | def fingerprint |
11 | [number, file, method].join | 14 | [number, file, method].join |
12 | end | 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 | end | 24 | end |
14 | 25 |
app/models/notice.rb
@@ -91,9 +91,8 @@ class Notice | @@ -91,9 +91,8 @@ class Notice | ||
91 | request['session'] || {} | 91 | request['session'] || {} |
92 | end | 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 | end | 96 | end |
98 | 97 | ||
99 | protected | 98 | protected |
app/views/mailer/err_notification.html.haml
@@ -27,16 +27,15 @@ | @@ -27,16 +27,15 @@ | ||
27 | %p.heading WHERE: | 27 | %p.heading WHERE: |
28 | %p.monospace | 28 | %p.monospace |
29 | = @notice.where | 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 | %br | 32 | %br |
34 | %p.heading URL: | 33 | %p.heading URL: |
35 | %p.monospace | 34 | %p.monospace |
36 | - if @notice.request['url'].present? | 35 | - if @notice.request['url'].present? |
37 | = link_to @notice.request['url'], @notice.request['url'] | 36 | = link_to @notice.request['url'], @notice.request['url'] |
38 | %p.heading BACKTRACE: | 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 | %p.backtrace= line | 39 | %p.backtrace= line |
41 | %br | 40 | %br |
42 | 41 |
app/views/mailer/err_notification.text.erb
@@ -14,7 +14,7 @@ WHERE: | @@ -14,7 +14,7 @@ WHERE: | ||
14 | 14 | ||
15 | <%= @notice.where %> | 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 | <%= line %> | 18 | <%= line %> |
19 | <% end %> | 19 | <% end %> |
20 | 20 | ||
@@ -26,7 +26,7 @@ URL: | @@ -26,7 +26,7 @@ URL: | ||
26 | 26 | ||
27 | BACKTRACE: | 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 | <%= line %> | 30 | <%= line %> |
31 | <% end %> | 31 | <% end %> |
32 | 32 |
app/views/notices/_backtrace_line.html.haml
1 | %tr{:class => defined?(row_class) ? row_class : nil} | 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 | = link_to_source_file(@app, line) do | 3 | = link_to_source_file(@app, line) do |
4 | %span.path>= path_for_backtrace_line(line) | 4 | %span.path>= path_for_backtrace_line(line) |
5 | %span.file>= file_for_backtrace_line(line) | 5 | %span.file>= file_for_backtrace_line(line) |