summaryrefslogtreecommitdiff
path: root/std/fs
diff options
context:
space:
mode:
Diffstat (limited to 'std/fs')
-rw-r--r--std/fs/copy.ts4
-rw-r--r--std/fs/empty_dir.ts14
-rw-r--r--std/fs/ensure_dir.ts6
-rw-r--r--std/fs/ensure_file.ts6
-rw-r--r--std/fs/ensure_link_test.ts6
-rw-r--r--std/fs/exists.ts14
-rw-r--r--std/fs/expand_glob.ts6
-rw-r--r--std/fs/walk_test.ts9
8 files changed, 23 insertions, 42 deletions
diff --git a/std/fs/copy.ts b/std/fs/copy.ts
index 86fac78df..ec51784c6 100644
--- a/std/fs/copy.ts
+++ b/std/fs/copy.ts
@@ -29,7 +29,7 @@ async function ensureValidCopy(
try {
destStat = await Deno.lstat(dest);
} catch (err) {
- if (err instanceof Deno.DenoError && err.kind == Deno.ErrorKind.NotFound) {
+ if (err instanceof Deno.Err.NotFound) {
return;
}
throw err;
@@ -57,7 +57,7 @@ function ensureValidCopySync(
try {
destStat = Deno.lstatSync(dest);
} catch (err) {
- if (err instanceof Deno.DenoError && err.kind == Deno.ErrorKind.NotFound) {
+ if (err instanceof Deno.Err.NotFound) {
return;
}
throw err;
diff --git a/std/fs/empty_dir.ts b/std/fs/empty_dir.ts
index e3d08ef70..0ac5e6420 100644
--- a/std/fs/empty_dir.ts
+++ b/std/fs/empty_dir.ts
@@ -1,14 +1,6 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { join } from "../path/mod.ts";
-const {
- readDir,
- readDirSync,
- mkdir,
- mkdirSync,
- remove,
- removeSync,
- ErrorKind
-} = Deno;
+const { readDir, readDirSync, mkdir, mkdirSync, remove, removeSync } = Deno;
/**
* Ensures that a directory is empty.
* Deletes directory contents if the directory is not empty.
@@ -28,7 +20,7 @@ export async function emptyDir(dir: string): Promise<void> {
}
}
} catch (err) {
- if ((err as Deno.DenoError<Deno.ErrorKind>).kind !== ErrorKind.NotFound) {
+ if (!(err instanceof Deno.Err.NotFound)) {
throw err;
}
@@ -57,7 +49,7 @@ export function emptyDirSync(dir: string): void {
}
}
} catch (err) {
- if ((err as Deno.DenoError<Deno.ErrorKind>).kind !== ErrorKind.NotFound) {
+ if (!(err instanceof Deno.Err.NotFound)) {
throw err;
}
// if not exist. then create it
diff --git a/std/fs/ensure_dir.ts b/std/fs/ensure_dir.ts
index d4b30dd2d..b6cc3150a 100644
--- a/std/fs/ensure_dir.ts
+++ b/std/fs/ensure_dir.ts
@@ -1,6 +1,6 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { getFileInfoType } from "./utils.ts";
-const { lstat, lstatSync, mkdir, mkdirSync, ErrorKind } = Deno;
+const { lstat, lstatSync, mkdir, mkdirSync } = Deno;
/**
* Ensures that the directory exists.
@@ -16,7 +16,7 @@ export async function ensureDir(dir: string): Promise<void> {
);
}
} catch (err) {
- if (err instanceof Deno.DenoError && err.kind === ErrorKind.NotFound) {
+ if (err instanceof Deno.Err.NotFound) {
// if dir not exists. then create it.
await mkdir(dir, { recursive: true });
return;
@@ -39,7 +39,7 @@ export function ensureDirSync(dir: string): void {
);
}
} catch (err) {
- if (err instanceof Deno.DenoError && err.kind == ErrorKind.NotFound) {
+ if (err instanceof Deno.Err.NotFound) {
// if dir not exists. then create it.
mkdirSync(dir, { recursive: true });
return;
diff --git a/std/fs/ensure_file.ts b/std/fs/ensure_file.ts
index 06c65b5f7..be824b7ba 100644
--- a/std/fs/ensure_file.ts
+++ b/std/fs/ensure_file.ts
@@ -2,7 +2,7 @@
import * as path from "../path/mod.ts";
import { ensureDir, ensureDirSync } from "./ensure_dir.ts";
import { getFileInfoType } from "./utils.ts";
-const { lstat, lstatSync, writeFile, writeFileSync, ErrorKind } = Deno;
+const { lstat, lstatSync, writeFile, writeFileSync } = Deno;
/**
* Ensures that the file exists.
@@ -23,7 +23,7 @@ export async function ensureFile(filePath: string): Promise<void> {
}
} catch (err) {
// if file not exists
- if (err instanceof Deno.DenoError && err.kind === ErrorKind.NotFound) {
+ if (err instanceof Deno.Err.NotFound) {
// ensure dir exists
await ensureDir(path.dirname(filePath));
// create file
@@ -54,7 +54,7 @@ export function ensureFileSync(filePath: string): void {
}
} catch (err) {
// if file not exists
- if (err instanceof Deno.DenoError && err.kind === ErrorKind.NotFound) {
+ if (err instanceof Deno.Err.NotFound) {
// ensure dir exists
ensureDirSync(path.dirname(filePath));
// create file
diff --git a/std/fs/ensure_link_test.ts b/std/fs/ensure_link_test.ts
index 6e9804152..7549814a2 100644
--- a/std/fs/ensure_link_test.ts
+++ b/std/fs/ensure_link_test.ts
@@ -143,8 +143,7 @@ Deno.test(async function ensureLinkDirectoryIfItExist(): Promise<void> {
await assertThrowsAsync(
async (): Promise<void> => {
await ensureLink(testDir, linkDir);
- },
- Deno.DenoError
+ }
// "Operation not permitted (os error 1)" // throw an local matching test
// "Access is denied. (os error 5)" // throw in CI
);
@@ -163,8 +162,7 @@ Deno.test(function ensureLinkSyncDirectoryIfItExist(): void {
assertThrows(
(): void => {
ensureLinkSync(testDir, linkDir);
- },
- Deno.DenoError
+ }
// "Operation not permitted (os error 1)" // throw an local matching test
// "Access is denied. (os error 5)" // throw in CI
);
diff --git a/std/fs/exists.ts b/std/fs/exists.ts
index 4584dbff9..2cd415173 100644
--- a/std/fs/exists.ts
+++ b/std/fs/exists.ts
@@ -1,5 +1,5 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
-const { lstat, lstatSync, DenoError, ErrorKind } = Deno;
+const { lstat, lstatSync } = Deno;
/**
* Test whether or not the given path exists by checking with the file system
*/
@@ -7,10 +7,8 @@ export async function exists(filePath: string): Promise<boolean> {
return lstat(filePath)
.then((): boolean => true)
.catch((err: Error): boolean => {
- if (err instanceof DenoError) {
- if (err.kind === ErrorKind.NotFound) {
- return false;
- }
+ if (err instanceof Deno.Err.NotFound) {
+ return false;
}
throw err;
@@ -25,10 +23,8 @@ export function existsSync(filePath: string): boolean {
lstatSync(filePath);
return true;
} catch (err) {
- if (err instanceof DenoError) {
- if (err.kind === ErrorKind.NotFound) {
- return false;
- }
+ if (err instanceof Deno.Err.NotFound) {
+ return false;
}
throw err;
}
diff --git a/std/fs/expand_glob.ts b/std/fs/expand_glob.ts
index aabf4a8a1..61fca9602 100644
--- a/std/fs/expand_glob.ts
+++ b/std/fs/expand_glob.ts
@@ -10,9 +10,7 @@ import {
} from "../path/mod.ts";
import { WalkInfo, walk, walkSync } from "./walk.ts";
import { assert } from "../testing/asserts.ts";
-const { ErrorKind, cwd, stat, statSync } = Deno;
-type ErrorKind = Deno.ErrorKind;
-type DenoError = Deno.DenoError<ErrorKind>;
+const { cwd, stat, statSync } = Deno;
type FileInfo = Deno.FileInfo;
export interface ExpandGlobOptions extends GlobOptions {
@@ -45,7 +43,7 @@ function split(path: string): SplitPath {
}
function throwUnlessNotFound(error: Error): void {
- if ((error as DenoError).kind != ErrorKind.NotFound) {
+ if (!(error instanceof Deno.Err.NotFound)) {
throw error;
}
}
diff --git a/std/fs/walk_test.ts b/std/fs/walk_test.ts
index 4984546f2..f99f82eb5 100644
--- a/std/fs/walk_test.ts
+++ b/std/fs/walk_test.ts
@@ -1,7 +1,5 @@
-const { DenoError, ErrorKind, cwd, chdir, makeTempDir, mkdir, open } = Deno;
+const { cwd, chdir, makeTempDir, mkdir, open } = Deno;
const { remove } = Deno;
-type ErrorKind = Deno.ErrorKind;
-type DenoError = Deno.DenoError<ErrorKind>;
import { walk, walkSync, WalkOptions, WalkInfo } from "./walk.ts";
import { assertEquals, assertThrowsAsync } from "../testing/asserts.ts";
@@ -235,10 +233,9 @@ testWalk(
testWalk(
async (_d: string): Promise<void> => {},
async function nonexistentRoot(): Promise<void> {
- const error = (await assertThrowsAsync(async () => {
+ await assertThrowsAsync(async () => {
await walkArray("nonexistent");
- }, DenoError)) as DenoError;
- assertEquals(error.kind, ErrorKind.NotFound);
+ }, Deno.Err.NotFound);
}
);