feat(runtime): improve error messages of runtime fs (#11984)

This commit annotates errors returned from FS Deno APIs to include
paths that were passed to the API calls.

Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
This commit is contained in:
Feng Yu 2021-10-11 21:21:18 +08:00 committed by GitHub
parent 423b02d889
commit 668b400ff2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 589 additions and 135 deletions

View file

@ -40,15 +40,23 @@ unitTest({ permissions: { read: false } }, function readDirSyncPerm() {
});
unitTest({ permissions: { read: true } }, function readDirSyncNotDir() {
assertThrows(() => {
Deno.readDirSync("cli/tests/testdata/fixture.json");
}, Error);
assertThrows(
() => {
Deno.readDirSync("cli/tests/testdata/fixture.json");
},
Error,
`readdir 'cli/tests/testdata/fixture.json'`,
);
});
unitTest({ permissions: { read: true } }, function readDirSyncNotFound() {
assertThrows(() => {
Deno.readDirSync("bad_dir_name");
}, Deno.errors.NotFound);
assertThrows(
() => {
Deno.readDirSync("bad_dir_name");
},
Deno.errors.NotFound,
`readdir 'bad_dir_name'`,
);
});
unitTest({ permissions: { read: true } }, async function readDirSuccess() {
@ -94,3 +102,13 @@ unitTest(
}
},
);
unitTest({ permissions: { read: true } }, async function readDirNotFound() {
await assertRejects(
async () => {
await Deno.readDir("bad_dir_name")[Symbol.asyncIterator]().next();
},
Deno.errors.NotFound,
`readdir 'bad_dir_name'`,
);
});