aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src/installation
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-02-21 14:59:46 +0000
committerAleksey Kladov <[email protected]>2020-02-22 15:03:47 +0000
commit49844ab717d8d1790dbdf7f44d160936ece0e80f (patch)
tree42c009ba902ecdda6d22daa8063fcb19f20408c7 /editors/code/src/installation
parent2cbe8a4c4be2a69b27c248ab96341c2336f983cd (diff)
Extract client-side logging
Diffstat (limited to 'editors/code/src/installation')
-rw-r--r--editors/code/src/installation/download_artifact.ts2
-rw-r--r--editors/code/src/installation/download_file.ts7
-rw-r--r--editors/code/src/installation/fetch_artifact_release_info.ts3
-rw-r--r--editors/code/src/installation/server.ts19
4 files changed, 16 insertions, 15 deletions
diff --git a/editors/code/src/installation/download_artifact.ts b/editors/code/src/installation/download_artifact.ts
index 9996c556f..356723aba 100644
--- a/editors/code/src/installation/download_artifact.ts
+++ b/editors/code/src/installation/download_artifact.ts
@@ -29,7 +29,6 @@ export async function downloadArtifact(
29 29
30 const installationPath = path.join(installationDir, artifactFileName); 30 const installationPath = path.join(installationDir, artifactFileName);
31 31
32 console.time(`Downloading ${artifactFileName}`);
33 await vscode.window.withProgress( 32 await vscode.window.withProgress(
34 { 33 {
35 location: vscode.ProgressLocation.Notification, 34 location: vscode.ProgressLocation.Notification,
@@ -54,5 +53,4 @@ export async function downloadArtifact(
54 ); 53 );
55 } 54 }
56 ); 55 );
57 console.timeEnd(`Downloading ${artifactFileName}`);
58} 56}
diff --git a/editors/code/src/installation/download_file.ts b/editors/code/src/installation/download_file.ts
index d154f4816..319cb995c 100644
--- a/editors/code/src/installation/download_file.ts
+++ b/editors/code/src/installation/download_file.ts
@@ -3,6 +3,7 @@ import * as fs from "fs";
3import * as stream from "stream"; 3import * as stream from "stream";
4import * as util from "util"; 4import * as util from "util";
5import { strict as assert } from "assert"; 5import { strict as assert } from "assert";
6import { log } from "../util";
6 7
7const pipeline = util.promisify(stream.pipeline); 8const pipeline = util.promisify(stream.pipeline);
8 9
@@ -21,8 +22,8 @@ export async function downloadFile(
21 const res = await fetch(url); 22 const res = await fetch(url);
22 23
23 if (!res.ok) { 24 if (!res.ok) {
24 console.log("Error", res.status, "while downloading file from", url); 25 log.error("Error", res.status, "while downloading file from", url);
25 console.dir({ body: await res.text(), headers: res.headers }, { depth: 3 }); 26 log.error({ body: await res.text(), headers: res.headers });
26 27
27 throw new Error(`Got response ${res.status} when trying to download a file.`); 28 throw new Error(`Got response ${res.status} when trying to download a file.`);
28 } 29 }
@@ -30,7 +31,7 @@ export async function downloadFile(
30 const totalBytes = Number(res.headers.get('content-length')); 31 const totalBytes = Number(res.headers.get('content-length'));
31 assert(!Number.isNaN(totalBytes), "Sanity check of content-length protocol"); 32 assert(!Number.isNaN(totalBytes), "Sanity check of content-length protocol");
32 33
33 console.log("Downloading file of", totalBytes, "bytes size from", url, "to", destFilePath); 34 log.debug("Downloading file of", totalBytes, "bytes size from", url, "to", destFilePath);
34 35
35 let readBytes = 0; 36 let readBytes = 0;
36 res.body.on("data", (chunk: Buffer) => { 37 res.body.on("data", (chunk: Buffer) => {
diff --git a/editors/code/src/installation/fetch_artifact_release_info.ts b/editors/code/src/installation/fetch_artifact_release_info.ts
index 1e764718c..1b6fc8d48 100644
--- a/editors/code/src/installation/fetch_artifact_release_info.ts
+++ b/editors/code/src/installation/fetch_artifact_release_info.ts
@@ -1,5 +1,6 @@
1import fetch from "node-fetch"; 1import fetch from "node-fetch";
2import { GithubRepo, ArtifactReleaseInfo } from "./interfaces"; 2import { GithubRepo, ArtifactReleaseInfo } from "./interfaces";
3import { log } from "../util";
3 4
4const GITHUB_API_ENDPOINT_URL = "https://api.github.com"; 5const GITHUB_API_ENDPOINT_URL = "https://api.github.com";
5 6
@@ -24,7 +25,7 @@ export async function fetchArtifactReleaseInfo(
24 25
25 // We skip runtime type checks for simplicity (here we cast from `any` to `GithubRelease`) 26 // We skip runtime type checks for simplicity (here we cast from `any` to `GithubRelease`)
26 27
27 console.log("Issuing request for released artifacts metadata to", requestUrl); 28 log.debug("Issuing request for released artifacts metadata to", requestUrl);
28 29
29 // FIXME: handle non-ok response 30 // FIXME: handle non-ok response
30 const response: GithubRelease = await fetch(requestUrl, { 31 const response: GithubRelease = await fetch(requestUrl, {
diff --git a/editors/code/src/installation/server.ts b/editors/code/src/installation/server.ts
index 750852921..685abfdc6 100644
--- a/editors/code/src/installation/server.ts
+++ b/editors/code/src/installation/server.ts
@@ -7,6 +7,7 @@ import { spawnSync } from "child_process";
7import { BinarySource } from "./interfaces"; 7import { BinarySource } from "./interfaces";
8import { fetchArtifactReleaseInfo } from "./fetch_artifact_release_info"; 8import { fetchArtifactReleaseInfo } from "./fetch_artifact_release_info";
9import { downloadArtifact } from "./download_artifact"; 9import { downloadArtifact } from "./download_artifact";
10import { log } from "../util";
10 11
11export async function ensureServerBinary(source: null | BinarySource): Promise<null | string> { 12export async function ensureServerBinary(source: null | BinarySource): Promise<null | string> {
12 if (!source) { 13 if (!source) {
@@ -40,7 +41,7 @@ export async function ensureServerBinary(source: null | BinarySource): Promise<n
40 const installedVersion: null | string = getServerVersion(source.storage); 41 const installedVersion: null | string = getServerVersion(source.storage);
41 const requiredVersion: string = source.version; 42 const requiredVersion: string = source.version;
42 43
43 console.log("Installed version:", installedVersion, "required:", requiredVersion); 44 log.debug("Installed version:", installedVersion, "required:", requiredVersion);
44 45
45 if (isBinaryAvailable(prebuiltBinaryPath) && installedVersion === requiredVersion) { 46 if (isBinaryAvailable(prebuiltBinaryPath) && installedVersion === requiredVersion) {
46 return prebuiltBinaryPath; 47 return prebuiltBinaryPath;
@@ -72,16 +73,16 @@ async function downloadServer(source: BinarySource.GithubRelease): Promise<boole
72 `GitHub repository: ${err.message}` 73 `GitHub repository: ${err.message}`
73 ); 74 );
74 75
75 console.error(err); 76 log.error(err);
76 77
77 dns.resolve('example.com').then( 78 dns.resolve('example.com').then(
78 addrs => console.log("DNS resolution for example.com was successful", addrs), 79 addrs => log.debug("DNS resolution for example.com was successful", addrs),
79 err => { 80 err => {
80 console.error( 81 log.error(
81 "DNS resolution for example.com failed, " + 82 "DNS resolution for example.com failed, " +
82 "there might be an issue with Internet availability" 83 "there might be an issue with Internet availability"
83 ); 84 );
84 console.error(err); 85 log.error(err);
85 } 86 }
86 ); 87 );
87 return false; 88 return false;
@@ -105,19 +106,19 @@ function isBinaryAvailable(binaryPath: string): boolean {
105 // ACHTUNG! `res` type declaration is inherently wrong, see 106 // ACHTUNG! `res` type declaration is inherently wrong, see
106 // https://github.com/DefinitelyTyped/DefinitelyTyped/issues/42221 107 // https://github.com/DefinitelyTyped/DefinitelyTyped/issues/42221
107 108
108 console.log("Checked binary availablity via --version", res); 109 log.debug("Checked binary availablity via --version", res);
109 console.log(binaryPath, "--version output:", res.output?.map(String)); 110 log.debug(binaryPath, "--version output:", res.output?.map(String));
110 111
111 return res.status === 0; 112 return res.status === 0;
112} 113}
113 114
114function getServerVersion(storage: vscode.Memento): null | string { 115function getServerVersion(storage: vscode.Memento): null | string {
115 const version = storage.get<null | string>("server-version", null); 116 const version = storage.get<null | string>("server-version", null);
116 console.log("Get server-version:", version); 117 log.debug("Get server-version:", version);
117 return version; 118 return version;
118} 119}
119 120
120async function setServerVersion(storage: vscode.Memento, version: string): Promise<void> { 121async function setServerVersion(storage: vscode.Memento, version: string): Promise<void> {
121 console.log("Set server-version:", version); 122 log.debug("Set server-version:", version);
122 await storage.update("server-version", version.toString()); 123 await storage.update("server-version", version.toString());
123} 124}