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

[document-updater] add missing await (#31034)

Co-authored-by: Brian Gough <brian.gough@overleaf.com>
GitOrigin-RevId: f0602801ce80ca617027004ad36f71c1e6cdcdd2
Jakob Ackermann 8 месяцев назад
Родитель
Сommit
86b29819c2

+ 15 - 7
services/document-updater/app/js/HistoryManager.js

@@ -96,13 +96,21 @@ async function resyncProjectHistory(
   if (opts.resyncProjectStructureOnly) return
   const DocumentManager = require('./DocumentManager')
 
-  await promiseMapWithLimit(MAX_PARALLEL_REQUESTS, docs, doc => {
-    DocumentManager.promises.resyncDocContentsWithLock(
-      projectId,
-      doc.doc,
-      doc.path,
-      opts
-    )
+  await promiseMapWithLimit(MAX_PARALLEL_REQUESTS, docs, async doc => {
+    const { doc: docId, path } = doc
+    try {
+      await DocumentManager.promises.resyncDocContentsWithLock(
+        projectId,
+        docId,
+        path,
+        opts
+      )
+    } catch (err) {
+      throw OError.tag(err, 'resyncDocContents', {
+        projectId,
+        docId,
+      })
+    }
   })
 }
 

+ 17 - 0
services/document-updater/test/unit/js/HistoryManager/HistoryManagerTests.js

@@ -1,6 +1,7 @@
 /* eslint-disable
     mocha/no-nested-tests,
 */
+const { expect } = require('chai')
 const SandboxedModule = require('sandboxed-module')
 const sinon = require('sinon')
 const modulePath = require('node:path').join(
@@ -206,6 +207,22 @@ describe('HistoryManager', function () {
       ]
     })
 
+    describe('error', function () {
+      it('should throw directly', async function () {
+        const err = new Error()
+        this.DocumentManager.promises.resyncDocContentsWithLock.rejects(err)
+        await expect(
+          this.HistoryManager.promises.resyncProjectHistory(
+            this.project_id,
+            this.projectHistoryId,
+            this.docs,
+            this.files,
+            {}
+          )
+        ).to.be.rejectedWith(err)
+      })
+    })
+
     describe('full sync', function () {
       beforeEach(async function () {
         await this.HistoryManager.promises.resyncProjectHistory(