diff options
author | Veetaha <[email protected]> | 2020-02-13 20:21:19 +0000 |
---|---|---|
committer | Veetaha <[email protected]> | 2020-02-13 20:21:19 +0000 |
commit | da6ae3b6e0700acf80eeb27b513abdd381c50916 (patch) | |
tree | b8787cb2e9ddd7988449c358904f83a8dee2e893 /editors/code | |
parent | a3febc1c574b9f99120b0e5bc860bf2458d0b919 (diff) |
vscode: replaced DownloadFileError with NestedError itself for simplicity
Diffstat (limited to 'editors/code')
-rw-r--r-- | editors/code/src/installation/download_file.ts | 13 |
1 files changed, 7 insertions, 6 deletions
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"; | |||
7 | 7 | ||
8 | const pipeline = util.promisify(stream.pipeline); | 8 | const pipeline = util.promisify(stream.pipeline); |
9 | 9 | ||
10 | class DownloadFileError extends NestedError {} | ||
11 | |||
12 | /** | 10 | /** |
13 | * Downloads file from `url` and stores it at `destFilePath` with `destFilePermissions`. | 11 | * Downloads file from `url` and stores it at `destFilePath` with `destFilePermissions`. |
14 | * `onProgress` callback is called on recieveing each chunk of bytes | 12 | * `onProgress` callback is called on recieveing each chunk of bytes |
@@ -21,13 +19,13 @@ export async function downloadFile( | |||
21 | destFilePermissions: number, | 19 | destFilePermissions: number, |
22 | onProgress: (readBytes: number, totalBytes: number) => void | 20 | onProgress: (readBytes: number, totalBytes: number) => void |
23 | ): Promise<void> { | 21 | ): Promise<void> { |
24 | const res = await fetch(url).catch(DownloadFileError.rethrow("Failed at initial fetch")); | 22 | const res = await fetch(url).catch(NestedError.rethrow("Failed at initial fetch")); |
25 | 23 | ||
26 | if (!res.ok) { | 24 | if (!res.ok) { |
27 | console.log("Error", res.status, "while downloading file from", url); | 25 | console.log("Error", res.status, "while downloading file from", url); |
28 | console.dir({ body: await res.text(), headers: res.headers }, { depth: 3 }); | 26 | console.dir({ body: await res.text(), headers: res.headers }, { depth: 3 }); |
29 | 27 | ||
30 | throw new DownloadFileError(`Got response ${res.status}`); | 28 | throw new NestedError(`Got response ${res.status}`); |
31 | } | 29 | } |
32 | 30 | ||
33 | const totalBytes = Number(res.headers.get('content-length')); | 31 | const totalBytes = Number(res.headers.get('content-length')); |
@@ -43,9 +41,12 @@ export async function downloadFile( | |||
43 | 41 | ||
44 | const destFileStream = fs.createWriteStream(destFilePath, { mode: destFilePermissions }); | 42 | const destFileStream = fs.createWriteStream(destFilePath, { mode: destFilePermissions }); |
45 | 43 | ||
46 | await pipeline(res.body, destFileStream).catch(DownloadFileError.rethrow("Piping file error")); | 44 | await pipeline(res.body, destFileStream).catch(NestedError.rethrow("Piping file error")); |
47 | return new Promise<void>(resolve => { | 45 | return new Promise<void>(resolve => { |
48 | destFileStream.on("close", resolve); // details on workaround: https://github.com/rust-analyzer/rust-analyzer/pull/3092#discussion_r378191131 | 46 | destFileStream.on("close", resolve); |
49 | destFileStream.destroy(); | 47 | destFileStream.destroy(); |
48 | |||
49 | // Details on workaround: https://github.com/rust-analyzer/rust-analyzer/pull/3092#discussion_r378191131 | ||
50 | // Issue at nodejs repo: https://github.com/nodejs/node/issues/31776 | ||
50 | }); | 51 | }); |
51 | } | 52 | } |