Skip to content

Commit

Permalink
Attempt to read a non-existing file should throw ENOENT
Browse files Browse the repository at this point in the history
I break it a bit in #174 😢
  • Loading branch information
Artem Sapegin committed Jul 5, 2018
1 parent 3463019 commit 322a730
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/__tests__/volume.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 6 additions & 3 deletions src/volume.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 322a730

Please sign in to comment.