Skip to content

Commit

Permalink
fix(readdirSync): 🐛 Error no such file or directory
Browse files Browse the repository at this point in the history
* `readdirSync` throws `ENOENT: no such file or directory, scandir` when
   the directory does not exists one of the file systems.
* Problem solved checking also if there are some results before throw.

Fixes #240
  • Loading branch information
magarcia committed Oct 17, 2019
1 parent 5cef73d commit b6c5764
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
26 changes: 26 additions & 0 deletions src/__tests__/union.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,32 @@ describe('union', () => {
ufs.use(vol2 as any);
expect(ufs.readdirSync("/foo")).toEqual(["bar", "baz", "qux"]);
});

it("reads other fss when one fails", () => {
const vol = Volume.fromJSON({
"/foo/bar": "bar",
"/foo/baz": "baz"
});
const vol2 = Volume.fromJSON({
"/bar/baz": "not baz",
"/bar/qux": "baz"
});

const ufs = new Union();
ufs.use(vol as any);
ufs.use(vol2 as any);
expect(ufs.readdirSync("/bar")).toEqual(["baz", "qux"]);
});

it("throws error when all fss fail", () => {
const vol = Volume.fromJSON({});
const vol2 = Volume.fromJSON({});

const ufs = new Union();
ufs.use(vol as any);
ufs.use(vol2 as any);
expect(() => ufs.readdirSync("/bar")).toThrow();
});
});
});
describe('async methods', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/union.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ export class Union {
} catch(err) {
err.prev = lastError;
lastError = err;
if(!i) { // last one
if(result.size === 0 && !i) { // last one
throw err;
} else {
// Ignore error...
Expand Down

0 comments on commit b6c5764

Please sign in to comment.