From da6ae3b6e0700acf80eeb27b513abdd381c50916 Mon Sep 17 00:00:00 2001 From: Veetaha Date: Thu, 13 Feb 2020 22:21:19 +0200 Subject: vscode: replaced DownloadFileError with NestedError itself for simplicity --- editors/code/src/installation/download_file.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'editors') diff --git a/editors/code/src/installation/download_file.ts b/editors/code/src/installation/download_file.ts index b31d2a736..591de0d31 100644 --- a/editors/code/src/installation/download_file.ts +++ b/editors/code/src/installation/download_file.ts @@ -7,8 +7,6 @@ import { NestedError } from "ts-nested-error"; const pipeline = util.promisify(stream.pipeline); -class DownloadFileError extends NestedError {} - /** * Downloads file from `url` and stores it at `destFilePath` with `destFilePermissions`. * `onProgress` callback is called on recieveing each chunk of bytes @@ -21,13 +19,13 @@ export async function downloadFile( destFilePermissions: number, onProgress: (readBytes: number, totalBytes: number) => void ): Promise { - const res = await fetch(url).catch(DownloadFileError.rethrow("Failed at initial fetch")); + const res = await fetch(url).catch(NestedError.rethrow("Failed at initial fetch")); if (!res.ok) { console.log("Error", res.status, "while downloading file from", url); console.dir({ body: await res.text(), headers: res.headers }, { depth: 3 }); - throw new DownloadFileError(`Got response ${res.status}`); + throw new NestedError(`Got response ${res.status}`); } const totalBytes = Number(res.headers.get('content-length')); @@ -43,9 +41,12 @@ export async function downloadFile( const destFileStream = fs.createWriteStream(destFilePath, { mode: destFilePermissions }); - await pipeline(res.body, destFileStream).catch(DownloadFileError.rethrow("Piping file error")); + await pipeline(res.body, destFileStream).catch(NestedError.rethrow("Piping file error")); return new Promise(resolve => { - destFileStream.on("close", resolve); // details on workaround: https://github.com/rust-analyzer/rust-analyzer/pull/3092#discussion_r378191131 + destFileStream.on("close", resolve); destFileStream.destroy(); + + // Details on workaround: https://github.com/rust-analyzer/rust-analyzer/pull/3092#discussion_r378191131 + // Issue at nodejs repo: https://github.com/nodejs/node/issues/31776 }); } -- cgit v1.2.3