Start passing more context to Discourse.handle_exception

This commit is contained in:
riking
2014-07-17 13:22:46 -07:00
parent 2b5a955c18
commit 12cb682548
12 changed files with 109 additions and 39 deletions

View File

@@ -117,22 +117,37 @@ describe Discourse do
end
context "#handle_exception" do
class TempLogger
class TempSidekiqLogger < Sidekiq::ExceptionHandler::Logger
attr_accessor :exception, :context
def handle_exception(exception, context)
self.exception = exception
self.context = context
def call(ex, ctx)
self.exception = ex
self.context = ctx
end
end
let!(:logger) { TempSidekiqLogger.new }
before do
Sidekiq.error_handlers.clear
Sidekiq.error_handlers << logger
end
it "should not fail when called" do
logger = TempLogger.new
exception = StandardError.new
Discourse.handle_exception(exception, nil, logger)
Discourse.handle_exception(exception, nil, nil)
logger.exception.should == exception
logger.context.keys.should == [:current_db, :current_hostname]
end
it "correctly passes extra context" do
exception = StandardError.new
Discourse.handle_exception(exception, {code: "Doing a test", post_id: 31}, nil)
logger.exception.should == exception
logger.context.keys.sort.should == [:current_db, :current_hostname, :code, :post_id].sort
end
end
end

View File

@@ -27,13 +27,13 @@ describe Jobs::Base do
end
it 'handles errors in multisite' do
RailsMultisite::ConnectionManagement.expects(:all_dbs).returns(['default','default'])
# just stub so logs are not noisy
Discourse.expects(:handle_exception).returns(nil)
RailsMultisite::ConnectionManagement.expects(:all_dbs).returns(['default','default','default'])
# one exception per database
Discourse.expects(:handle_exception).times(3)
bad = BadJob.new
expect{bad.perform({})}.to raise_error
bad.fail_count.should == 2
bad.fail_count.should == 3
end
it 'delegates the process call to execute' do