Просмотр исходного кода

Merge pull request #20979 from overleaf/jpa-handle-error

[project-history] gracefully handle errors when loading Changes

GitOrigin-RevId: 214fadb3c779551ea90f38b0fdf77c58ed5df178
Jakob Ackermann 2 лет назад
Родитель
Сommit
fab69a16c4

+ 14 - 6
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(

+ 23 - 0
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 () {