From fab69a16c46c9591e040bbb1097a61979ae8e115 Mon Sep 17 00:00:00 2001 From: Jakob Ackermann Date: Mon, 14 Oct 2024 16:51:42 +0200 Subject: [PATCH] Merge pull request #20979 from overleaf/jpa-handle-error [project-history] gracefully handle errors when loading Changes GitOrigin-RevId: 214fadb3c779551ea90f38b0fdf77c58ed5df178 --- .../app/js/UpdatesProcessor.js | 20 +++++++++++----- .../UpdatesManager/UpdatesProcessorTests.js | 23 +++++++++++++++++++ 2 files changed, 37 insertions(+), 6 deletions(-) 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 () {