vscode: removed nested errors as per matklad

This commit is contained in:
Veetaha
2020-02-14 00:31:23 +02:00
parent da6ae3b6e0
commit 574dc11a2f
3 changed files with 3 additions and 10 deletions

View File

@@ -753,11 +753,6 @@
"os-tmpdir": "~1.0.1" "os-tmpdir": "~1.0.1"
} }
}, },
"ts-nested-error": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/ts-nested-error/-/ts-nested-error-1.1.3.tgz",
"integrity": "sha512-CJSRAhXr6phdkuu65U/ctkY/TBzjkg2g1sL9juSG/PP3ONQNCbeksMy54OfCBTUt13hSpHNbnTO1OBPunOHj/Q=="
},
"tslib": { "tslib": {
"version": "1.10.0", "version": "1.10.0",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-1.10.0.tgz", "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.10.0.tgz",

View File

@@ -27,7 +27,6 @@
"jsonc-parser": "^2.1.0", "jsonc-parser": "^2.1.0",
"node-fetch": "^2.6.0", "node-fetch": "^2.6.0",
"throttle-debounce": "^2.1.0", "throttle-debounce": "^2.1.0",
"ts-nested-error": "^1.1.3",
"vscode-languageclient": "^6.1.0" "vscode-languageclient": "^6.1.0"
}, },
"devDependencies": { "devDependencies": {

View File

@@ -3,7 +3,6 @@ import * as fs from "fs";
import * as stream from "stream"; import * as stream from "stream";
import * as util from "util"; import * as util from "util";
import { strict as assert } from "assert"; import { strict as assert } from "assert";
import { NestedError } from "ts-nested-error";
const pipeline = util.promisify(stream.pipeline); const pipeline = util.promisify(stream.pipeline);
@@ -19,13 +18,13 @@ export async function downloadFile(
destFilePermissions: number, destFilePermissions: number,
onProgress: (readBytes: number, totalBytes: number) => void onProgress: (readBytes: number, totalBytes: number) => void
): Promise<void> { ): Promise<void> {
const res = await fetch(url).catch(NestedError.rethrow("Failed at initial fetch")); const res = await fetch(url);
if (!res.ok) { if (!res.ok) {
console.log("Error", res.status, "while downloading file from", url); console.log("Error", res.status, "while downloading file from", url);
console.dir({ body: await res.text(), headers: res.headers }, { depth: 3 }); console.dir({ body: await res.text(), headers: res.headers }, { depth: 3 });
throw new NestedError(`Got response ${res.status}`); throw new Error(`Got response ${res.status} when trying to download a file.`);
} }
const totalBytes = Number(res.headers.get('content-length')); const totalBytes = Number(res.headers.get('content-length'));
@@ -41,7 +40,7 @@ export async function downloadFile(
const destFileStream = fs.createWriteStream(destFilePath, { mode: destFilePermissions }); const destFileStream = fs.createWriteStream(destFilePath, { mode: destFilePermissions });
await pipeline(res.body, destFileStream).catch(NestedError.rethrow("Piping file error")); await pipeline(res.body, destFileStream);
return new Promise<void>(resolve => { return new Promise<void>(resolve => {
destFileStream.on("close", resolve); destFileStream.on("close", resolve);
destFileStream.destroy(); destFileStream.destroy();