Don't crash when logging out error

This commit is contained in:
James Allen 2014-03-04 12:39:02 +00:00
parent 86195ce7c3
commit 5d45e191f3
2 changed files with 17 additions and 2 deletions

View file

@ -34,7 +34,7 @@ module.exports = TrackChangesManager =
logger.log length: length, doc_id: doc_id, "flushing track changes api" logger.log length: length, doc_id: doc_id, "flushing track changes api"
TrackChangesManager.flushDocChanges doc_id, (error) -> TrackChangesManager.flushDocChanges doc_id, (error) ->
if error? if error?
logger.error err: error, project_id: project_id, doc_id: doc_id, "error flushing doc to track changes api" logger.error err: error, doc_id: doc_id, "error flushing doc to track changes api"
callback() callback()
else else
callback() callback()

View file

@ -8,7 +8,7 @@ describe "TrackChangesManager", ->
@TrackChangesManager = SandboxedModule.require modulePath, requires: @TrackChangesManager = SandboxedModule.require modulePath, requires:
"request": @request = {} "request": @request = {}
"settings-sharelatex": @Settings = {} "settings-sharelatex": @Settings = {}
"logger-sharelatex": @logger = { log: sinon.stub() } "logger-sharelatex": @logger = { log: sinon.stub(), error: sinon.stub() }
"./RedisManager": @RedisManager = {} "./RedisManager": @RedisManager = {}
@doc_id = "mock-doc-id" @doc_id = "mock-doc-id"
@callback = sinon.stub() @callback = sinon.stub()
@ -76,6 +76,21 @@ describe "TrackChangesManager", ->
.calledWith(@doc_id) .calledWith(@doc_id)
.should.equal true .should.equal true
describe "when TrackChangesManager errors", ->
beforeEach ->
@RedisManager.pushUncompressedHistoryOp =
sinon.stub().callsArgWith(2, null, 2 * @TrackChangesManager.FLUSH_EVERY_N_OPS)
@TrackChangesManager.flushDocChanges = sinon.stub().callsArgWith(1, @error = new Error("oops"))
@TrackChangesManager.pushUncompressedHistoryOp @doc_id, @op, @callback
it "should log out the error", ->
@logger.error
.calledWith(
err: @error
doc_id: @doc_id
"error flushing doc to track changes api"
)
.should.equal true
describe "when the doc is over the load manager threshold", -> describe "when the doc is over the load manager threshold", ->
beforeEach -> beforeEach ->