aboutsummaryrefslogtreecommitdiff
path: root/editors
diff options
context:
space:
mode:
authorVeetaha <[email protected]>2020-02-28 22:26:22 +0000
committerVeetaha <[email protected]>2020-02-28 22:26:22 +0000
commit3ad0574d7e3f1af1e28f7f5cbc085faa30759e47 (patch)
treede0192925c1b4bcdad592401771fe4344b11a3e7 /editors
parent9cf25770542dfbf35c710f7c214f65ecaad39100 (diff)
vscode: add equality assertion
Diffstat (limited to 'editors')
-rw-r--r--editors/code/src/installation/download_artifact.ts4
-rw-r--r--editors/code/src/util.ts10
2 files changed, 12 insertions, 2 deletions
diff --git a/editors/code/src/installation/download_artifact.ts b/editors/code/src/installation/download_artifact.ts
index 8ed99bf0a..c60014c8c 100644
--- a/editors/code/src/installation/download_artifact.ts
+++ b/editors/code/src/installation/download_artifact.ts
@@ -1,10 +1,10 @@
1import * as vscode from "vscode"; 1import * as vscode from "vscode";
2import * as path from "path"; 2import * as path from "path";
3import { promises as fs } from "fs"; 3import { promises as fs } from "fs";
4import { strict as assert } from "assert";
5 4
6import { ArtifactReleaseInfo } from "./interfaces"; 5import { ArtifactReleaseInfo } from "./interfaces";
7import { downloadFile } from "./download_file"; 6import { downloadFile } from "./download_file";
7import { assert } from "../util";
8 8
9/** 9/**
10 * Downloads artifact from given `downloadUrl`. 10 * Downloads artifact from given `downloadUrl`.
@@ -19,7 +19,7 @@ export async function downloadArtifact(
19 installationDir: string, 19 installationDir: string,
20 displayName: string, 20 displayName: string,
21) { 21) {
22 await fs.mkdir(installationDir).catch(err => assert.strictEqual( 22 await fs.mkdir(installationDir).catch(err => assert.eq(
23 err?.code, 23 err?.code,
24 "EEXIST", 24 "EEXIST",
25 `Couldn't create directory "${installationDir}" to download ` + 25 `Couldn't create directory "${installationDir}" to download ` +
diff --git a/editors/code/src/util.ts b/editors/code/src/util.ts
index 733bdc8c5..5a5f11a10 100644
--- a/editors/code/src/util.ts
+++ b/editors/code/src/util.ts
@@ -11,6 +11,16 @@ export function assert(condition: unknown, explanation: string): asserts conditi
11 } 11 }
12} 12}
13 13
14assert.eq = <T>(bibba: unknown, bobba: T, explanation: string): asserts bibba is T => {
15 try {
16 nativeAssert.strictEqual(bibba, bobba, explanation);
17 } catch (err) {
18 log.error(`Equality assertion failed:`, explanation);
19 throw err;
20 }
21}
22
23
14export const log = { 24export const log = {
15 enabled: true, 25 enabled: true,
16 debug(message?: any, ...optionalParams: any[]): void { 26 debug(message?: any, ...optionalParams: any[]): void {