diff --git a/app/assets/javascripts/errbit.js b/app/assets/javascripts/errbit.js index bedcbb6..6dd92fb 100644 --- a/app/assets/javascripts/errbit.js +++ b/app/assets/javascripts/errbit.js @@ -71,6 +71,9 @@ $(function() { tab.closest('.tab-bar').find('a.active').removeClass('active'); tab.addClass('active'); + // If clicking into 'backtrace' tab, hide external backtrace + if (tab.attr('rel') == "backtrace") { hide_external_backtrace(); } + $('.panel').hide(); panel.show(); } @@ -94,11 +97,17 @@ $(function() { }); } - init(); - - // Show external backtrace lines when clicking separator - $('td.backtrace_separator span').live('click', function(){ - $('tr.hidden_external_backtrace').removeClass('hidden_external_backtrace'); + function hide_external_backtrace() { + $('tr.toggle_external_backtrace').hide(); + $('td.backtrace_separator').show(); + } + function show_external_backtrace() { + $('tr.toggle_external_backtrace').show(); $('td.backtrace_separator').hide(); - }); + } + // Show external backtrace lines when clicking separator + $('td.backtrace_separator span').live('click', show_external_backtrace); + // Hide external backtrace on page load + hide_external_backtrace(); + init(); }); diff --git a/app/assets/stylesheets/errbit.css b/app/assets/stylesheets/errbit.css index 1fe7176..75a6079 100644 --- a/app/assets/stylesheets/errbit.css +++ b/app/assets/stylesheets/errbit.css @@ -741,27 +741,28 @@ table.backtrace td.line { vertical-align: top; white-space: nowrap; } - table.backtrace td.line .file { - color: #ededed; - font-weight:bold; -} -table.backtrace td.line .file a { - color: #21A4FF; + font-weight: bold; } - table.backtrace td.line .method { color: #aaa; - font-weight:bold; + font-weight: bold; } table.backtrace td.line.in-app { color: #2adb2e; background-color: #2f2f2f; } -table.backtrace td.line.in-app .file { color: #2AEB2E; } +table.backtrace td.line.in-app .path, +table.backtrace td.line.in-app .number { color: #2ACB2E; } +table.backtrace td.line.in-app .file { color: #3AFB3E; } table.backtrace td.line.in-app .method { color: #2ACB2E; } +table.backtrace td.line.in-app a .path, +table.backtrace td.line.in-app a .number, +table.backtrace td.line.in-app a:hover { color: #21B4FF; } +table.backtrace td.line.in-app a .file { color: #31C4FF; } + /* External backtrace classes and separators */ table.backtrace tr.hidden_external_backtrace { display: none; diff --git a/app/helpers/notices_helper.rb b/app/helpers/notices_helper.rb index 964fb4e..37e0968 100644 --- a/app/helpers/notices_helper.rb +++ b/app/helpers/notices_helper.rb @@ -1,11 +1,16 @@ # encoding: utf-8 module NoticesHelper - def notice_atom_summary notice + def in_app_backtrace_line?(line) + !!(line['file'] =~ %r{^\[PROJECT_ROOT\]/(?!(vendor))}) + end + + def notice_atom_summary(notice) render :partial => "notices/atom_entry.html.haml", :locals => {:notice => notice} end - def link_to_source_file(app, line, text) - if Notice.in_app_backtrace_line?(line) + def link_to_source_file(app, line, &block) + text = capture_haml(&block) + if in_app_backtrace_line?(line) return link_to_github(app, line, text) if app.github_url? if app.issue_tracker && app.issue_tracker.respond_to?(:url_to_file) # Return link to file on tracker if issue tracker supports this @@ -36,7 +41,7 @@ module NoticesHelper def grouped_lines(lines) line_groups = [] lines.each do |line| - in_app = Notice.in_app_backtrace_line?(line) + in_app = in_app_backtrace_line?(line) if line_groups.last && line_groups.last[0] == in_app line_groups.last[1] << line else @@ -48,12 +53,16 @@ module NoticesHelper def path_for_backtrace_line(line) path = File.dirname(line['file']) - path == "." ? "" : path + '/' + return '' if path == '.' + # Remove [PROJECT_ROOT] + path.gsub!('[PROJECT_ROOT]/', '') + # Make gem name bold if starts with [GEM_ROOT]/gems + path.gsub!(/\[GEM_ROOT\]\/gems\/([^\/]+)/, "\\1") + (path << '/').html_safe end def file_for_backtrace_line(line) file = File.basename(line['file']) - line['number'].present? ? "#{file}:#{line['number']}" : file end end diff --git a/app/models/notice.rb b/app/models/notice.rb index 85cafb8..014fbdf 100644 --- a/app/models/notice.rb +++ b/app/models/notice.rb @@ -62,10 +62,6 @@ class Notice where end - def self.in_app_backtrace_line?(line) - !!(line['file'] =~ %r{^\[PROJECT_ROOT\]/(?!(vendor))}) - end - def request read_attribute(:request) || {} end diff --git a/app/views/notices/_backtrace.html.haml b/app/views/notices/_backtrace.html.haml index 26afc63..9ccddd8 100644 --- a/app/views/notices/_backtrace.html.haml +++ b/app/views/notices/_backtrace.html.haml @@ -2,11 +2,11 @@ %table.backtrace -# Group lines into internal / external so we can toggle the external backtrace -# Includes a margin of x lines that are not toggled. - - em = 3 # (external backtrace margin) + - em = 4 # (external backtrace margin) - grouped_lines(lines).each do |in_app, line_group| - if !in_app && line_group.size > (em * 3) = render :partial => 'notices/backtrace_line', :collection => line_group[0, em], :as => :line - = render :partial => 'notices/backtrace_line', :collection => line_group[em, line_group.size - (em * 2)], :as => :line, :locals => {:row_class => 'hidden_external_backtrace'} + = render :partial => 'notices/backtrace_line', :collection => line_group[em, line_group.size - (em * 2)], :as => :line, :locals => {:row_class => 'toggle_external_backtrace'} %tr %td.line.backtrace_separator %span ... diff --git a/app/views/notices/_backtrace_line.html.haml b/app/views/notices/_backtrace_line.html.haml index ec48cf8..56db410 100644 --- a/app/views/notices/_backtrace_line.html.haml +++ b/app/views/notices/_backtrace_line.html.haml @@ -1,6 +1,9 @@ %tr{:class => defined?(row_class) ? row_class : nil} - %td.line{:class => (Notice.in_app_backtrace_line?(line) ? 'in-app' : nil)} - %span.path>= path_for_backtrace_line(line) - %span.file= link_to_source_file(@app, line, file_for_backtrace_line(line)).html_safe + %td.line{:class => (in_app_backtrace_line?(line) ? 'in-app' : nil)} + = link_to_source_file(@app, line) do + %span.path>= path_for_backtrace_line(line) + %span.file>= file_for_backtrace_line(line) + - if line['number'].present? + %span.number>= ":#{line['number']}" → %span.method= line['method'] diff --git a/spec/models/notice_spec.rb b/spec/models/notice_spec.rb index dcf7223..eafb35c 100644 --- a/spec/models/notice_spec.rb +++ b/spec/models/notice_spec.rb @@ -24,36 +24,6 @@ describe Notice do end - context '.in_app_backtrace_line?' do - let(:backtrace) do [{ - 'number' => rand(999), - 'file' => '[GEM_ROOT]/gems/actionpack-3.0.4/lib/action_controller/metal/rescue.rb', - 'method' => ActiveSupport.methods.shuffle.first - }, { - 'number' => rand(999), - 'file' => '[PROJECT_ROOT]/vendor/plugins/seamless_database_pool/lib/seamless_database_pool/controller_filter.rb', - 'method' => ActiveSupport.methods.shuffle.first - }, { - 'number' => rand(999), - 'file' => '[PROJECT_ROOT]/lib/set_headers.rb', - 'method' => ActiveSupport.methods.shuffle.first - }] - end - - it "should be false for line not starting with PROJECT_ROOT" do - Notice.in_app_backtrace_line?(backtrace[0]).should == false - end - - it "should be false for file in vendor dir" do - Notice.in_app_backtrace_line?(backtrace[1]).should == false - end - - it "should be true for application file" do - Notice.in_app_backtrace_line?(backtrace[2]).should == true - end - end - - describe "key sanitization" do before do @hash = { "some.key" => { "$nested.key" => {"$Path" => "/", "some$key" => "key"}}} -- libgit2 0.21.2