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

[project-history] gracefully handle errors when loading Changes

GitOrigin-RevId: 214fadb3c779551ea90f38b0fdf77c58ed5df178
This commit is contained in:
Jakob Ackermann 2024-10-14 16:51:42 +02:00 committed by Copybot
parent 663f6605d7
commit fab69a16c4
2 changed files with 37 additions and 6 deletions

View file

@ -408,12 +408,20 @@ export function _processUpdates(
)
},
(updatesWithBlobs, cb) => {
const changes = UpdateTranslator.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(

View file

@ -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 () {