refactor: remove unneeded ErrorKinds (#3936)

This commit is contained in:
Bartek Iwańczuk 2020-02-21 10:36:13 -05:00 committed by GitHub
parent d9efb8c02a
commit dd8a109481
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
66 changed files with 553 additions and 620 deletions

View file

@ -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;

View file

@ -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

View file

@ -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;

View file

@ -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

View file

@ -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
);

View file

@ -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;
}

View file

@ -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;
}
}

View file

@ -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);
}
);