diff --git a/src/fsa-to-node/FsaNodeCore.ts b/src/fsa-to-node/FsaNodeCore.ts index fe81ed82c..6da020b08 100644 --- a/src/fsa-to-node/FsaNodeCore.ts +++ b/src/fsa-to-node/FsaNodeCore.ts @@ -54,8 +54,14 @@ export class FsaNodeCore { curr = await curr.getDirectoryHandle(name, options); } } catch (error) { - if (error && typeof error === 'object' && error.name === 'TypeMismatchError') - throw createError('ENOTDIR', funcName, path.join(FsaToNodeConstants.Separator)); + if (error && typeof error === 'object') { + switch (error.name) { + case 'TypeMismatchError': + throw createError('ENOTDIR', funcName, path.join(FsaToNodeConstants.Separator)); + case 'NotFoundError': + throw createError('ENOENT', funcName, path.join(FsaToNodeConstants.Separator)); + } + } throw error; } return curr; @@ -86,7 +92,18 @@ export class FsaNodeCore { if (error && typeof error === 'object') { switch (error.name) { case 'TypeMismatchError': - return await dir.getDirectoryHandle(name); + try { + return await dir.getDirectoryHandle(name); + } catch (error2) { + if (error2 && typeof error2 === 'object') { + switch (error2.name) { + case 'TypeMismatchError': + throw createError('ENOTDIR', funcName, path.join(FsaToNodeConstants.Separator)); + case 'NotFoundError': + throw createError('ENOENT', funcName, path.join(FsaToNodeConstants.Separator)); + } + } + } case 'NotFoundError': throw createError('ENOENT', funcName, path.join(FsaToNodeConstants.Separator)); } diff --git a/src/fsa-to-node/__tests__/FsaNodeFs.test.ts b/src/fsa-to-node/__tests__/FsaNodeFs.test.ts index 62aedf279..d35408f7a 100644 --- a/src/fsa-to-node/__tests__/FsaNodeFs.test.ts +++ b/src/fsa-to-node/__tests__/FsaNodeFs.test.ts @@ -527,6 +527,18 @@ onlyOnNode20('FsaNodeFs', () => { expect(stats.isFile()).toBe(true); }); + test('throws "ENOENT" when path is not found', async () => { + const { fs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' }); + const [, error] = await of(fs.promises.stat('/folder/repo/.git')); + expect((error).code).toBe('ENOENT'); + }); + + test('throws "ENOTDIR" when sub-folder is a file', async () => { + const { fs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' }); + const [, error] = await of(fs.promises.stat('/folder/file/repo/.git')); + expect((error).code).toBe('ENOTDIR'); + }); + test('can retrieve file size', async () => { const { fs, mfs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' }); const stats = await fs.promises.stat('/folder/file');