diff --git a/services/web/app/src/Features/Project/ProjectLocator.mjs b/services/web/app/src/Features/Project/ProjectLocator.mjs index 24d3505903..8cce19d00b 100644 --- a/services/web/app/src/Features/Project/ProjectLocator.mjs +++ b/services/web/app/src/Features/Project/ProjectLocator.mjs @@ -167,7 +167,9 @@ async function _findElementByPathWithProject( } } if (!found) { - throw new Errors.NotFoundError('parent folder not found in project', { + throw new Errors.NotFoundError( + 'parent folder not found in project' + ).withInfo({ projectId: project._id, needlePath, needleFolderName, @@ -204,7 +206,7 @@ async function _findElementByPathWithProject( if (result != null) { return { element: result, type, folder } } - throw new Errors.NotFoundError('element not found in project', { + throw new Errors.NotFoundError('element not found in project').withInfo({ projectId: project._id, needlePath, entityName, diff --git a/services/web/test/unit/src/Project/ProjectLocator.test.mjs b/services/web/test/unit/src/Project/ProjectLocator.test.mjs index 7d3f9b9361..da94dabdf5 100644 --- a/services/web/test/unit/src/Project/ProjectLocator.test.mjs +++ b/services/web/test/unit/src/Project/ProjectLocator.test.mjs @@ -1,5 +1,6 @@ import { vi, expect } from 'vitest' import sinon from 'sinon' +import OError from '@overleaf/o-error' import Errors from '../../../../app/src/Features/Errors/Errors.js' const modulePath = '../../../../app/src/Features/Project/ProjectLocator' @@ -412,18 +413,36 @@ describe('ProjectLocator', function () { it('should return an error if the file can not be found inside know folder', async function (ctx) { const path = `${subFolder.name}/${secondSubFolder.name}/exist.txt` - await expect(ctx.locator.promises.findElementByPath({ project, path })).to - .eventually.be.rejected + let error + try { + await ctx.locator.promises.findElementByPath({ project, path }) + } catch (err) { + error = err + } + expect(error).to.be.instanceOf(Errors.NotFoundError) + expect(error.message).to.equal('element not found in project') + expect(OError.getFullInfo(error)).to.eql({ + projectId: project._id, + needlePath: path, + entityName: 'exist.txt', + }) }) it('should return an error if the file can not be found inside unknown folder', async function (ctx) { const path = 'this/does/not/exist.txt' - await expect( - ctx.locator.promises.findElementByPath({ - project, - path, - }) - ).to.eventually.be.rejected + let error + try { + await ctx.locator.promises.findElementByPath({ project, path }) + } catch (err) { + error = err + } + expect(error).to.be.instanceOf(Errors.NotFoundError) + expect(error.message).to.equal('parent folder not found in project') + expect(OError.getFullInfo(error)).to.eql({ + projectId: project._id, + needlePath: path, + needleFolderName: 'this', + }) }) describe('where duplicate folder exists', function () {