diff --git a/services/project-history/app/js/UpdatesProcessor.js b/services/project-history/app/js/UpdatesProcessor.js index 73fb47828d..3b1be3c22d 100644 --- a/services/project-history/app/js/UpdatesProcessor.js +++ b/services/project-history/app/js/UpdatesProcessor.js @@ -408,12 +408,20 @@ export function _processUpdates( ) }, (updatesWithBlobs, cb) => { - const changes = UpdateTranslator.convertToChanges( - projectId, - updatesWithBlobs - ).map(change => change.toRaw()) - profile.log('convertToChanges') - + let changes + try { + changes = UpdateTranslator.convertToChanges( + projectId, + updatesWithBlobs + ).map(change => change.toRaw()) + } catch (err) { + return cb(err) + } finally { + profile.log('convertToChanges') + } + cb(null, changes) + }, + (changes, cb) => { let change const numChanges = changes.length const byteLength = Buffer.byteLength( diff --git a/services/project-history/test/unit/js/UpdatesManager/UpdatesProcessorTests.js b/services/project-history/test/unit/js/UpdatesManager/UpdatesProcessorTests.js index d2d5122ee1..a5d2846cbc 100644 --- a/services/project-history/test/unit/js/UpdatesManager/UpdatesProcessorTests.js +++ b/services/project-history/test/unit/js/UpdatesManager/UpdatesProcessorTests.js @@ -390,6 +390,29 @@ describe('UpdatesProcessor', function () { return this.callback.should.have.been.called }) }) + + describe('with an error converting changes', function () { + beforeEach(function (done) { + this.err = new Error() + this.UpdateTranslator.convertToChanges.throws(this.err) + this.callback = sinon.stub() + + this.UpdatesProcessor._processUpdates( + this.project_id, + this.ol_project_id, + this.rawUpdates, + this.extendLock, + err => { + this.callback(err) + done() + } + ) + }) + + it('should call the callback with the error', function () { + this.callback.should.have.been.calledWith(this.err) + }) + }) }) return describe('_skipAlreadyAppliedUpdates', function () {