From b906de86db0735078292311b77a6025e88c8f3cd Mon Sep 17 00:00:00 2001 From: Alf Eaton Date: Mon, 11 May 2026 10:37:49 +0100 Subject: [PATCH] Add info to NotFoundError (#33440) * Add info to errors in ProjectLocator * Update ProjectLocator.test.mjs * Add info to errors in SSOConfigManager * Update SSOConfigManager.test.mjs GitOrigin-RevId: 5a13350af1808f3a16a4bc8a9946cbe8f15e6b3a --- .../src/Features/Project/ProjectLocator.mjs | 6 ++-- .../unit/src/Project/ProjectLocator.test.mjs | 35 ++++++++++++++----- 2 files changed, 31 insertions(+), 10 deletions(-) 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 () {