From 3ad0574d7e3f1af1e28f7f5cbc085faa30759e47 Mon Sep 17 00:00:00 2001 From: Veetaha Date: Sat, 29 Feb 2020 00:26:22 +0200 Subject: vscode: add equality assertion --- editors/code/src/installation/download_artifact.ts | 4 ++-- editors/code/src/util.ts | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) (limited to 'editors') 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 @@ import * as vscode from "vscode"; import * as path from "path"; import { promises as fs } from "fs"; -import { strict as assert } from "assert"; import { ArtifactReleaseInfo } from "./interfaces"; import { downloadFile } from "./download_file"; +import { assert } from "../util"; /** * Downloads artifact from given `downloadUrl`. @@ -19,7 +19,7 @@ export async function downloadArtifact( installationDir: string, displayName: string, ) { - await fs.mkdir(installationDir).catch(err => assert.strictEqual( + await fs.mkdir(installationDir).catch(err => assert.eq( err?.code, "EEXIST", `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 } } +assert.eq = (bibba: unknown, bobba: T, explanation: string): asserts bibba is T => { + try { + nativeAssert.strictEqual(bibba, bobba, explanation); + } catch (err) { + log.error(`Equality assertion failed:`, explanation); + throw err; + } +} + + export const log = { enabled: true, debug(message?: any, ...optionalParams: any[]): void { -- cgit v1.2.3