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
This commit is contained in:
Alf Eaton
2026-05-11 10:37:49 +01:00
committed by Copybot
parent 8be321fd73
commit b906de86db
2 changed files with 31 additions and 10 deletions
@@ -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,
@@ -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 () {