diff --git a/app/models/err.rb b/app/models/err.rb index b622a99..6014ea6 100644 --- a/app/models/err.rb +++ b/app/models/err.rb @@ -3,10 +3,10 @@ class Err include Mongoid::Timestamps field :klass - field :message field :component field :action field :environment + field :fingerprint field :resolved, :type => Boolean, :default => false referenced_in :project @@ -40,4 +40,8 @@ class Err where end + def message + notices.first.message || klass + end + end \ No newline at end of file diff --git a/app/models/notice.rb b/app/models/notice.rb index f731c6c..e6ed399 100644 --- a/app/models/notice.rb +++ b/app/models/notice.rb @@ -4,6 +4,7 @@ class Notice include Mongoid::Document include Mongoid::Timestamps + field :message field :backtrace, :type => Array field :server_environment, :type => Hash field :request, :type => Hash @@ -23,19 +24,20 @@ class Notice hoptoad_notice['request']['action'] = nil if hoptoad_notice['request']['action'].blank? error = Err.for({ - :project => project, - :klass => hoptoad_notice['error']['class'], - :message => hoptoad_notice['error']['message'], - :component => hoptoad_notice['request']['component'], - :action => hoptoad_notice['request']['action'], - :environment => hoptoad_notice['server-environment']['environment-name'] + :project => project, + :klass => hoptoad_notice['error']['class'], + :component => hoptoad_notice['request']['component'], + :action => hoptoad_notice['request']['action'], + :environment => hoptoad_notice['server-environment']['environment-name'], + :fingerprint => hoptoad_notice['fingerprint'] }) error.notices.create!({ - :backtrace => hoptoad_notice['error']['backtrace']['line'], + :message => hoptoad_notice['error']['message'], + :backtrace => hoptoad_notice['error']['backtrace']['line'], :server_environment => hoptoad_notice['server-environment'], - :request => hoptoad_notice['request'], - :notifier => hoptoad_notice['notifier'] + :request => hoptoad_notice['request'], + :notifier => hoptoad_notice['notifier'] }) end diff --git a/app/views/projects/index.html.haml b/app/views/projects/index.html.haml index 6d37564..d8f7e16 100644 --- a/app/views/projects/index.html.haml +++ b/app/views/projects/index.html.haml @@ -12,4 +12,10 @@ %tr %td.name= link_to project.name, project_path(project) %td.deploy= project.last_deploy_at ? project.last_deploy_at.to_s(:micro) : 'n/a' - %td.count= link_to project.errs.unresolved.count, project_errs_path(project) \ No newline at end of file + %td.count= link_to project.errs.unresolved.count, project_errs_path(project) + - if @projects.none? + %tr + %td{:colspan => 3} + %em + No projects here. + = link_to 'Click here to create your first one', new_project_path \ No newline at end of file diff --git a/lib/hoptoad.rb b/lib/hoptoad.rb index f7a8082..ee6d799 100644 --- a/lib/hoptoad.rb +++ b/lib/hoptoad.rb @@ -1,5 +1,7 @@ module Hoptoad module V2 + require 'digest/md5' + class ApiVersionError < StandardError def initialize super "Wrong API Version: Expecting v2.0" @@ -9,7 +11,9 @@ module Hoptoad def self.parse_xml(xml) parsed = ActiveSupport::XmlMini.backend.parse(xml)['notice'] raise ApiVersionError unless parsed && parsed['version'] == '2.0' - rekey(parsed) + rekeyed = rekey(parsed) + rekeyed['fingerprint'] = Digest::MD5.hexdigest(rekeyed['error']['backtrace'].to_s) + rekeyed end private diff --git a/spec/factories/err_factories.rb b/spec/factories/err_factories.rb index 4f16fdc..c9a6129 100644 --- a/spec/factories/err_factories.rb +++ b/spec/factories/err_factories.rb @@ -1,14 +1,14 @@ Factory.define :err do |e| e.project {|p| p.association :project} e.klass 'FooError' - e.message 'FooError: Too Much Bar' e.component 'foo' e.action 'bar' e.environment 'production' end Factory.define :notice do |n| - n.err {|e| e.association :err} + n.err {|e| e.association :err} + n.message 'FooError: Too Much Bar' n.backtrace { random_backtrace } n.server_environment 'server-environment' => 'production' n.notifier 'name' => 'Notifier', 'version' => '1', 'url' => 'http://toad.com' diff --git a/spec/models/err_spec.rb b/spec/models/err_spec.rb index 324e6d7..a82c2a9 100644 --- a/spec/models/err_spec.rb +++ b/spec/models/err_spec.rb @@ -22,7 +22,6 @@ describe Err do @conditions = { :project => @project, :klass => 'Whoops', - :message => 'Whoops: Oopsy Daisy', :component => 'Foo', :action => 'bar', :environment => 'production' @@ -59,6 +58,15 @@ describe Err do end end + context '#message' do + it 'returns the message from the first notice' do + err = Factory(:err) + notice1 = Factory(:notice, :err => err, :message => 'ERR 1') + notice2 = Factory(:notice, :err => err, :message => 'ERR 2') + err.message.should == notice1.message + end + end + context "#resolved?" do it "should start out as unresolved" do error = Err.new diff --git a/spec/models/notice_spec.rb b/spec/models/notice_spec.rb index aa2dfb3..fa76568 100644 --- a/spec/models/notice_spec.rb +++ b/spec/models/notice_spec.rb @@ -26,6 +26,7 @@ describe Notice do before do @xml = Rails.root.join('spec','fixtures','hoptoad_test_notice.xml').read @project = Factory(:project, :api_key => 'ALLGLORYTOTHEHYPNOTOAD') + Digest::MD5.stub(:hexdigest).and_return('fingerprintdigest') end it 'finds the correct project' do @@ -37,10 +38,10 @@ describe Notice do Err.should_receive(:for).with({ :project => @project, :klass => 'HoptoadTestingException', - :message => 'HoptoadTestingException: Testing hoptoad via "rake hoptoad:test". If you can see this, it works.', :component => 'application', :action => 'verify', - :environment => 'development' + :environment => 'development', + :fingerprint => 'fingerprintdigest' }).and_return(err = Err.new) err.notices.stub(:create!) @notice = Notice.from_xml(@xml) @@ -56,6 +57,11 @@ describe Notice do @notice.err.should be_a(Err) end + it 'captures the error message' do + @notice = Notice.from_xml(@xml) + @notice.message.should == 'HoptoadTestingException: Testing hoptoad via "rake hoptoad:test". If you can see this, it works.' + end + it 'captures the backtrace' do @notice = Notice.from_xml(@xml) @notice.backtrace.size.should == 73 -- libgit2 0.21.2