From 322a7304d8790334d964a44109bb83a3ed4b5830 Mon Sep 17 00:00:00 2001 From: Artem Sapegin Date: Thu, 5 Jul 2018 14:52:35 +0200 Subject: [PATCH] Attempt to read a non-existing file should throw ENOENT I break it a bit in #174 :cry: --- src/__tests__/volume.test.ts | 6 +++++- src/volume.ts | 9 ++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/__tests__/volume.test.ts b/src/__tests__/volume.test.ts index bdf4593d9..a80c5c44b 100644 --- a/src/__tests__/volume.test.ts +++ b/src/__tests__/volume.test.ts @@ -460,12 +460,16 @@ describe('volume', () => { // TODO: Check the right error message. } }); - it('Attempt to read a directory should throw', () => { + it('Attempt to read a directory should throw EISDIR', () => { const vol = new Volume; vol.mkdirSync('/test'); const fn = () => vol.readFileSync('/test'); expect(fn).toThrowError('EISDIR'); }); + it('Attempt to read a non-existing file should throw ENOENT', () => { + const fn = () => vol.readFileSync('/pizza.txt'); + expect(fn).toThrowError('ENOENT'); + }); }); describe('.readFile(path[, options], callback)', () => { const vol = new Volume; diff --git a/src/volume.ts b/src/volume.ts index f163ce22b..af2b2e81d 100644 --- a/src/volume.ts +++ b/src/volume.ts @@ -1017,9 +1017,12 @@ export class Volume { } else { const steps = filenameToSteps(id as string); const link: Link = this.getResolvedLink(steps); - const node = link.getNode(); - if(node.isDirectory()) - throwError(EISDIR, 'open', link.getPath()); + + if(link) { + const node = link.getNode(); + if(node.isDirectory()) + throwError(EISDIR, 'open', link.getPath()); + } fd = this.openSync(id as TFilePath, flagsNum); }