diff --git a/app/helpers/notices_helper.rb b/app/helpers/notices_helper.rb index 017f0a6..6bd5073 100644 --- a/app/helpers/notices_helper.rb +++ b/app/helpers/notices_helper.rb @@ -1,16 +1,12 @@ # encoding: utf-8 module NoticesHelper - def in_app_backtrace_line?(line) - !!(line['file'] =~ %r{^\[PROJECT_ROOT\]/(?!(vendor))}) - end - def notice_atom_summary(notice) render "notices/atom_entry.html.haml", :notice => notice end def link_to_source_file(app, line, &block) text = capture_haml(&block) - if in_app_backtrace_line?(line) + if line.in_app? return link_to_github(app, line, text) if app.github_repo? return link_to_bitbucket(app, line, text) if app.bitbucket_repo? if app.issue_tracker && app.issue_tracker.respond_to?(:url_to_file) @@ -48,7 +44,7 @@ module NoticesHelper def grouped_lines(lines) line_groups = [] lines.each do |line| - in_app = in_app_backtrace_line?(line) + in_app = line.in_app? if line_groups.last && line_groups.last[0] == in_app line_groups.last[1] << line else diff --git a/app/models/backtrace_line.rb b/app/models/backtrace_line.rb index e1e71d9..e74fa1c 100644 --- a/app/models/backtrace_line.rb +++ b/app/models/backtrace_line.rb @@ -1,5 +1,6 @@ class BacktraceLine include Mongoid::Document + IN_APP_REGEXP = %r{^\[PROJECT_ROOT\]\/(?!(vendor))} field :number, :type => Integer field :file @@ -7,8 +8,18 @@ class BacktraceLine embedded_in :backtrace + scope :in_app, where(:file => IN_APP_REGEXP) + def fingerprint [number, file, method].join end + + def to_s + "#{file}:#{number}" + end + + def in_app? + !!(file =~ IN_APP_REGEXP) + end end diff --git a/app/models/notice.rb b/app/models/notice.rb index f848f2f..29c30b5 100644 --- a/app/models/notice.rb +++ b/app/models/notice.rb @@ -91,9 +91,8 @@ class Notice request['session'] || {} end - # Backtrace containing only files from the app itself (ignore gems) - def app_backtrace - backtrace_lines.select { |l| l && l['file'] && l['file'].include?("[PROJECT_ROOT]") } + def in_app_backtrace_lines + backtrace_lines.in_app end protected diff --git a/app/views/mailer/err_notification.html.haml b/app/views/mailer/err_notification.html.haml index d6fbb23..ed9a4ea 100644 --- a/app/views/mailer/err_notification.html.haml +++ b/app/views/mailer/err_notification.html.haml @@ -27,16 +27,15 @@ %p.heading WHERE: %p.monospace = @notice.where - - if (app_backtrace = @notice.app_backtrace).any? - - app_backtrace.map {|l| "#{l['file']}:#{l['number']}" }.each do |line| - %p.backtrace= line + - @notice.in_app_backtrace_lines.each do |line| + %p.backtrace= line %br %p.heading URL: %p.monospace - if @notice.request['url'].present? = link_to @notice.request['url'], @notice.request['url'] %p.heading BACKTRACE: - - @notice.backtrace_lines.map {|l| l ? "#{l['file']}:#{l['number']}" : nil }.compact.each do |line| + - @notice.backtrace_lines.each do |line| %p.backtrace= line %br diff --git a/app/views/mailer/err_notification.text.erb b/app/views/mailer/err_notification.text.erb index 5c2151b..f9c1caa 100644 --- a/app/views/mailer/err_notification.text.erb +++ b/app/views/mailer/err_notification.text.erb @@ -14,7 +14,7 @@ WHERE: <%= @notice.where %> -<% @notice.app_backtrace.map {|l| "#{l['file']}:#{l['number']}" }.each do |line| %> +<% @notice.in_app_backtrace_lines.each do |line| %> <%= line %> <% end %> @@ -26,7 +26,7 @@ URL: BACKTRACE: -<% @notice.backtrace_lines.map {|l| l ? "#{l['file']}:#{l['number']}" : nil }.compact.each do |line| %> +<% @notice.backtrace_lines.each do |line| %> <%= line %> <% end %> diff --git a/app/views/notices/_backtrace_line.html.haml b/app/views/notices/_backtrace_line.html.haml index 56db410..ccc9a5a 100644 --- a/app/views/notices/_backtrace_line.html.haml +++ b/app/views/notices/_backtrace_line.html.haml @@ -1,5 +1,5 @@ %tr{:class => defined?(row_class) ? row_class : nil} - %td.line{:class => (in_app_backtrace_line?(line) ? 'in-app' : nil)} + %td.line{:class => line.in_app? && 'in-app' } = link_to_source_file(@app, line) do %span.path>= path_for_backtrace_line(line) %span.file>= file_for_backtrace_line(line) -- libgit2 0.21.2