mirror of
https://github.com/overleaf/overleaf.git
synced 2025-04-12 23:16:09 +00:00
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:
parent
41a706108c
commit
eb32081585
2 changed files with 50 additions and 0 deletions
|
@ -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'))
|
||||
}
|
||||
|
|
|
@ -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 () {
|
||||
|
|
Loading…
Add table
Reference in a new issue