From 559d808d859ad84f835e6207ac4717a8c0b14959 Mon Sep 17 00:00:00 2001 From: Robert Lail Date: Wed, 29 Aug 2012 19:48:13 -0500 Subject: [PATCH] Errs are like a hash table whose values are arrays of notices and whose keys are a composite of error_class + component + action + environment + backtrace[0..3]. --- app/models/app.rb | 6 ++++++ app/models/err.rb | 9 +++------ app/models/error_report.rb | 10 ---------- spec/fabricators/err_fabricator.rb | 5 +---- spec/models/app_spec.rb | 5 ++--- spec/models/err_spec.rb | 14 ++++++++++++++ 6 files changed, 26 insertions(+), 23 deletions(-) diff --git a/app/models/app.rb b/app/models/app.rb index e103e00..950ce70 100644 --- a/app/models/app.rb +++ b/app/models/app.rb @@ -42,6 +42,12 @@ class App accepts_nested_attributes_for :notification_service, :allow_destroy => true, :reject_if => proc { |attrs| !NotificationService.subclasses.map(&:to_s).include?(attrs[:type].to_s) } + # Acceps a hash with the following attributes: + # + # * :error_class - the class of error (required to create a new Problem) + # * :environment - the environment the source app was running in (required to create a new Problem) + # * :fingerprint - a unique value identifying the notice + # def find_or_create_err!(attrs) Err.where( :fingerprint => attrs[:fingerprint] diff --git a/app/models/err.rb b/app/models/err.rb index 477cd50..712fa98 100644 --- a/app/models/err.rb +++ b/app/models/err.rb @@ -6,19 +6,16 @@ class Err include Mongoid::Document include Mongoid::Timestamps - field :error_class, :default => "UnknownError" - field :component - field :action - field :environment, :default => "unknown" field :fingerprint - belongs_to :problem index :problem_id - index :error_class index :fingerprint + belongs_to :problem has_many :notices, :inverse_of => :err, :dependent => :destroy + validates_presence_of :problem_id, :fingerprint + delegate :app, :resolved?, :to => :problem end diff --git a/app/models/error_report.rb b/app/models/error_report.rb index dea4174..b00b5df 100644 --- a/app/models/error_report.rb +++ b/app/models/error_report.rb @@ -28,14 +28,6 @@ class ErrorReport rails_env end - def component - request['component'] || 'unknown' - end - - def action - request['action'] - end - def app @app ||= App.where(:api_key => api_key).first end @@ -71,8 +63,6 @@ class ErrorReport def error @error ||= app.find_or_create_err!( :error_class => error_class, - :component => component, - :action => action, :environment => rails_env, :fingerprint => fingerprint ) diff --git a/spec/fabricators/err_fabricator.rb b/spec/fabricators/err_fabricator.rb index f22ce5e..e1d87d3 100644 --- a/spec/fabricators/err_fabricator.rb +++ b/spec/fabricators/err_fabricator.rb @@ -1,9 +1,6 @@ Fabricator :err do problem! - error_class! { 'FooError' } - component 'foo' - action 'bar' - environment 'production' + fingerprint 'some-finger-print' end Fabricator :notice do diff --git a/spec/models/app_spec.rb b/spec/models/app_spec.rb index e67bca1..9367e4d 100644 --- a/spec/models/app_spec.rb +++ b/spec/models/app_spec.rb @@ -162,9 +162,8 @@ describe App do @app = Fabricate(:app) @conditions = { :error_class => 'Whoops', - :component => 'Foo', - :action => 'bar', - :environment => 'production' + :environment => 'production', + :fingerprint => 'some-finger-print' } end diff --git a/spec/models/err_spec.rb b/spec/models/err_spec.rb index 6a6599f..39b237c 100644 --- a/spec/models/err_spec.rb +++ b/spec/models/err_spec.rb @@ -2,4 +2,18 @@ require 'spec_helper' describe Err do + context 'validations' do + it 'requires a fingerprint' do + err = Fabricate.build(:err, :fingerprint => nil) + err.should_not be_valid + err.errors[:fingerprint].should include("can't be blank") + end + + it 'requires a problem' do + err = Fabricate.build(:err, :problem_id => nil) + err.should_not be_valid + err.errors[:problem_id].should include("can't be blank") + end + end + end -- libgit2 0.21.2