mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-12 13:13:45 +01:00
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:
@@ -167,7 +167,9 @@ async function _findElementByPathWithProject(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!found) {
|
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,
|
projectId: project._id,
|
||||||
needlePath,
|
needlePath,
|
||||||
needleFolderName,
|
needleFolderName,
|
||||||
@@ -204,7 +206,7 @@ async function _findElementByPathWithProject(
|
|||||||
if (result != null) {
|
if (result != null) {
|
||||||
return { element: result, type, folder }
|
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,
|
projectId: project._id,
|
||||||
needlePath,
|
needlePath,
|
||||||
entityName,
|
entityName,
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { vi, expect } from 'vitest'
|
import { vi, expect } from 'vitest'
|
||||||
import sinon from 'sinon'
|
import sinon from 'sinon'
|
||||||
|
import OError from '@overleaf/o-error'
|
||||||
import Errors from '../../../../app/src/Features/Errors/Errors.js'
|
import Errors from '../../../../app/src/Features/Errors/Errors.js'
|
||||||
|
|
||||||
const modulePath = '../../../../app/src/Features/Project/ProjectLocator'
|
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) {
|
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`
|
const path = `${subFolder.name}/${secondSubFolder.name}/exist.txt`
|
||||||
await expect(ctx.locator.promises.findElementByPath({ project, path })).to
|
let error
|
||||||
.eventually.be.rejected
|
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) {
|
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'
|
const path = 'this/does/not/exist.txt'
|
||||||
await expect(
|
let error
|
||||||
ctx.locator.promises.findElementByPath({
|
try {
|
||||||
project,
|
await ctx.locator.promises.findElementByPath({ project, path })
|
||||||
path,
|
} catch (err) {
|
||||||
})
|
error = err
|
||||||
).to.eventually.be.rejected
|
}
|
||||||
|
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 () {
|
describe('where duplicate folder exists', function () {
|
||||||
|
|||||||
Reference in New Issue
Block a user