Merge pull request #11974 from overleaf/jk-catch-errors-in-rename-file

[web] add logging to catch an error in renameEntity

GitOrigin-RevId: 74a942e87150a4fa94f7b1b46732de3df8b36389
This commit is contained in:
ilkin-overleaf 2023-02-28 11:17:02 +02:00 committed by Copybot
parent 41a706108c
commit eb32081585
2 changed files with 50 additions and 0 deletions

View file

@ -1302,6 +1302,19 @@ const ProjectEntityUpdateHandler = {
source,
callback
) {
if (!newName || typeof newName !== 'string') {
const err = new OError('invalid newName value', {
value: newName,
type: typeof newName,
projectId,
entityId,
entityType,
userId,
source,
})
logger.error({ err }, 'Invalid newName passed to renameEntity')
return callback(err)
}
if (!SafePath.isCleanFilename(newName)) {
return callback(new Errors.InvalidNameError('invalid element name'))
}

View file

@ -1913,6 +1913,43 @@ describe('ProjectEntityUpdateHandler', function () {
this.callback.calledWithMatch(errorMatcher).should.equal(true)
})
})
describe('renaming an entity with a non-string value', function () {
beforeEach(function () {
this.project_name = 'project name'
this.startPath = '/folder/a.tex'
this.endPath = '/folder/b.tex'
this.rev = 2
this.changes = { newDocs: ['old-doc'], newFiles: ['old-file'] }
this.newDocName = ['hello']
this.ProjectEntityMongoUpdateHandler.renameEntity.yields(
null,
this.project,
this.startPath,
this.endPath,
this.rev,
this.changes
)
this.ProjectEntityUpdateHandler.renameEntity(
projectId,
docId,
'doc',
this.newDocName,
userId,
this.source,
this.callback
)
})
it('returns an error', function () {
const errorMatcher = sinon.match.instanceOf(Error)
this.callback.calledWithMatch(errorMatcher).should.equal(true)
expect(
this.ProjectEntityMongoUpdateHandler.renameEntity.called
).to.equal(false)
})
})
})
describe('resyncProjectHistory', function () {