diff options
Diffstat (limited to 'editors/code')
-rw-r--r-- | editors/code/package-lock.json | 5 | ||||
-rw-r--r-- | editors/code/package.json | 1 | ||||
-rw-r--r-- | editors/code/src/installation/download_file.ts | 23 | ||||
-rw-r--r-- | editors/code/src/installation/language_server.ts | 2 |
4 files changed, 24 insertions, 7 deletions
diff --git a/editors/code/package-lock.json b/editors/code/package-lock.json index 5c056463e..e737d6ace 100644 --- a/editors/code/package-lock.json +++ b/editors/code/package-lock.json | |||
@@ -753,6 +753,11 @@ | |||
753 | "os-tmpdir": "~1.0.1" | 753 | "os-tmpdir": "~1.0.1" |
754 | } | 754 | } |
755 | }, | 755 | }, |
756 | "ts-nested-error": { | ||
757 | "version": "1.1.3", | ||
758 | "resolved": "https://registry.npmjs.org/ts-nested-error/-/ts-nested-error-1.1.3.tgz", | ||
759 | "integrity": "sha512-CJSRAhXr6phdkuu65U/ctkY/TBzjkg2g1sL9juSG/PP3ONQNCbeksMy54OfCBTUt13hSpHNbnTO1OBPunOHj/Q==" | ||
760 | }, | ||
756 | "tslib": { | 761 | "tslib": { |
757 | "version": "1.10.0", | 762 | "version": "1.10.0", |
758 | "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.10.0.tgz", | 763 | "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.10.0.tgz", |
diff --git a/editors/code/package.json b/editors/code/package.json index f687eb8d4..ce7117c69 100644 --- a/editors/code/package.json +++ b/editors/code/package.json | |||
@@ -27,6 +27,7 @@ | |||
27 | "jsonc-parser": "^2.1.0", | 27 | "jsonc-parser": "^2.1.0", |
28 | "node-fetch": "^2.6.0", | 28 | "node-fetch": "^2.6.0", |
29 | "throttle-debounce": "^2.1.0", | 29 | "throttle-debounce": "^2.1.0", |
30 | "ts-nested-error": "^1.1.3", | ||
30 | "vscode-languageclient": "^6.1.0" | 31 | "vscode-languageclient": "^6.1.0" |
31 | }, | 32 | }, |
32 | "devDependencies": { | 33 | "devDependencies": { |
diff --git a/editors/code/src/installation/download_file.ts b/editors/code/src/installation/download_file.ts index f1f9f4a25..71700ec8a 100644 --- a/editors/code/src/installation/download_file.ts +++ b/editors/code/src/installation/download_file.ts | |||
@@ -1,6 +1,9 @@ | |||
1 | import fetch from "node-fetch"; | 1 | import fetch from "node-fetch"; |
2 | import * as fs from "fs"; | 2 | import * as fs from "fs"; |
3 | import { strict as assert } from "assert"; | 3 | import { strict as assert } from "assert"; |
4 | import { NestedError } from "ts-nested-error"; | ||
5 | |||
6 | class DownloadFileError extends NestedError {} | ||
4 | 7 | ||
5 | /** | 8 | /** |
6 | * Downloads file from `url` and stores it at `destFilePath` with `destFilePermissions`. | 9 | * Downloads file from `url` and stores it at `destFilePath` with `destFilePermissions`. |
@@ -14,13 +17,13 @@ export async function downloadFile( | |||
14 | destFilePermissions: number, | 17 | destFilePermissions: number, |
15 | onProgress: (readBytes: number, totalBytes: number) => void | 18 | onProgress: (readBytes: number, totalBytes: number) => void |
16 | ): Promise<void> { | 19 | ): Promise<void> { |
17 | const res = await fetch(url); | 20 | const res = await fetch(url).catch(DownloadFileError.rethrow("Failed at initial fetch")); |
18 | 21 | ||
19 | if (!res.ok) { | 22 | if (!res.ok) { |
20 | console.log("Error", res.status, "while downloading file from", url); | 23 | console.log("Error", res.status, "while downloading file from", url); |
21 | console.dir({ body: await res.text(), headers: res.headers }, { depth: 3 }); | 24 | console.dir({ body: await res.text(), headers: res.headers }, { depth: 3 }); |
22 | 25 | ||
23 | throw new Error(`Got response ${res.status} when trying to download a file`); | 26 | throw new DownloadFileError(`Got response ${res.status}`); |
24 | } | 27 | } |
25 | 28 | ||
26 | const totalBytes = Number(res.headers.get('content-length')); | 29 | const totalBytes = Number(res.headers.get('content-length')); |
@@ -30,15 +33,21 @@ export async function downloadFile( | |||
30 | 33 | ||
31 | console.log("Downloading file of", totalBytes, "bytes size from", url, "to", destFilePath); | 34 | console.log("Downloading file of", totalBytes, "bytes size from", url, "to", destFilePath); |
32 | 35 | ||
36 | // Here reject() may be called 2 times. As per ECMAScript standard, 2-d call is ignored | ||
37 | // https://tc39.es/ecma262/#sec-promise-reject-functions | ||
38 | |||
33 | return new Promise<void>((resolve, reject) => res.body | 39 | return new Promise<void>((resolve, reject) => res.body |
34 | .on("data", (chunk: Buffer) => { | 40 | .on("data", (chunk: Buffer) => { |
35 | readBytes += chunk.length; | 41 | readBytes += chunk.length; |
36 | onProgress(readBytes, totalBytes); | 42 | onProgress(readBytes, totalBytes); |
37 | }) | 43 | }) |
38 | .on("error", reject) | 44 | .on("error", err => reject( |
39 | .pipe(fs | 45 | new DownloadFileError(`Read-stream error, read bytes: ${readBytes}`, err) |
40 | .createWriteStream(destFilePath, { mode: destFilePermissions }) | 46 | )) |
41 | .on("close", resolve) | 47 | .pipe(fs.createWriteStream(destFilePath, { mode: destFilePermissions })) |
42 | ) | 48 | .on("error", err => reject( |
49 | new DownloadFileError(`Write-stream error, read bytes: ${readBytes}`, err) | ||
50 | )) | ||
51 | .on("close", resolve) | ||
43 | ); | 52 | ); |
44 | } | 53 | } |
diff --git a/editors/code/src/installation/language_server.ts b/editors/code/src/installation/language_server.ts index 52c5cbe7d..4797c3f01 100644 --- a/editors/code/src/installation/language_server.ts +++ b/editors/code/src/installation/language_server.ts | |||
@@ -104,6 +104,8 @@ export async function ensureLanguageServerBinary( | |||
104 | `GitHub repository: ${err.message}` | 104 | `GitHub repository: ${err.message}` |
105 | ); | 105 | ); |
106 | 106 | ||
107 | console.error(err); | ||
108 | |||
107 | dns.resolve('example.com').then( | 109 | dns.resolve('example.com').then( |
108 | addrs => console.log("DNS resolution for example.com was successful", addrs), | 110 | addrs => console.log("DNS resolution for example.com was successful", addrs), |
109 | err => { | 111 | err => { |