Skip to content

Commit c490830

Browse files
committed
Use multiple args instead of string interpolation + Downgrader logging from error to warn
1 parent 36b388e commit c490830

File tree

1 file changed

+23
-24
lines changed

1 file changed

+23
-24
lines changed

src/storage.ts

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -129,28 +129,26 @@ export class Storage {
129129
const enableDownloads =
130130
vscode.workspace.getConfiguration().get("coder.enableDownloads") !==
131131
false;
132-
this.output.info(
133-
`Downloads are ${enableDownloads ? "enabled" : "disabled"}`,
134-
);
132+
this.output.info("Downloads are", enableDownloads ? "enabled" : "disabled");
135133

136134
// Get the build info to compare with the existing binary version, if any,
137135
// and to log for debugging.
138136
const buildInfo = await restClient.getBuildInfo();
139-
this.output.info(`Got server version: ${buildInfo.version}`);
137+
this.output.info("Got server version", buildInfo.version);
140138

141139
// Check if there is an existing binary and whether it looks valid. If it
142140
// is valid and matches the server, or if it does not match the server but
143141
// downloads are disabled, we can return early.
144142
const binPath = path.join(this.getBinaryCachePath(label), cli.name());
145-
this.output.info(`Using binary path: ${binPath}`);
143+
this.output.info("Using binary path", binPath);
146144
const stat = await cli.stat(binPath);
147145
if (stat === undefined) {
148146
this.output.info("No existing binary found, starting download");
149147
} else {
150-
this.output.info(`Existing binary size is ${prettyBytes(stat.size)}`);
148+
this.output.info("Existing binary size is", prettyBytes(stat.size));
151149
try {
152150
const version = await cli.version(binPath);
153-
this.output.info(`Existing binary version is ${version}`);
151+
this.output.info("Existing binary version is", version);
154152
// If we have the right version we can avoid the request entirely.
155153
if (version === buildInfo.version) {
156154
this.output.info(
@@ -167,26 +165,24 @@ export class Storage {
167165
"Downloading since existing binary does not match the server version",
168166
);
169167
} catch (error) {
170-
this.output.error(
168+
this.output.warn(
171169
`Unable to get version of existing binary: ${error}. Downloading new binary instead`,
172170
);
173171
}
174172
}
175173

176174
if (!enableDownloads) {
177-
this.output.error(
178-
"Unable to download CLI because downloads are disabled",
179-
);
175+
this.output.warn("Unable to download CLI because downloads are disabled");
180176
throw new Error("Unable to download CLI because downloads are disabled");
181177
}
182178

183179
// Remove any left-over old or temporary binaries.
184180
const removed = await cli.rmOld(binPath);
185181
removed.forEach(({ fileName, error }) => {
186182
if (error) {
187-
this.output.error(`Failed to remove ${fileName}: ${error}`);
183+
this.output.warn(`Failed to remove ${fileName}`, error);
188184
} else {
189-
this.output.info(`Removed ${fileName}`);
185+
this.output.info("Removed", fileName);
190186
}
191187
});
192188

@@ -199,12 +195,12 @@ export class Storage {
199195
configSource && String(configSource).trim().length > 0
200196
? String(configSource)
201197
: "/bin/" + binName;
202-
this.output.info(`Downloading binary from: ${binSource}`);
198+
this.output.info("Downloading binary from", binSource);
203199

204200
// Ideally we already caught that this was the right version and returned
205201
// early, but just in case set the ETag.
206202
const etag = stat !== undefined ? await cli.eTag(binPath) : "";
207-
this.output.info(`Using ETag: ${etag}`);
203+
this.output.info("Using ETag", etag);
208204

209205
// Make the download request.
210206
const controller = new AbortController();
@@ -220,18 +216,19 @@ export class Storage {
220216
// Ignore all errors so we can catch a 404!
221217
validateStatus: () => true,
222218
});
223-
this.output.info(`Got status code ${resp.status}`);
219+
this.output.info("Got status code", resp.status);
224220

225221
switch (resp.status) {
226222
case 200: {
227223
const rawContentLength = resp.headers["content-length"];
228224
const contentLength = Number.parseInt(rawContentLength);
229225
if (Number.isNaN(contentLength)) {
230-
this.output.error(
231-
`Got invalid or missing content length: ${rawContentLength}`,
226+
this.output.warn(
227+
"Got invalid or missing content length",
228+
rawContentLength,
232229
);
233230
} else {
234-
this.output.info(`Got content length: ${prettyBytes(contentLength)}`);
231+
this.output.info("Got content length", prettyBytes(contentLength));
235232
}
236233

237234
// Download to a temporary file.
@@ -312,7 +309,7 @@ export class Storage {
312309
// False means the user canceled, although in practice it appears we
313310
// would not get this far because VS Code already throws on cancelation.
314311
if (!completed) {
315-
this.output.error("User aborted download");
312+
this.output.warn("User aborted download");
316313
throw new Error("User aborted download");
317314
}
318315

@@ -327,25 +324,27 @@ export class Storage {
327324
const oldBinPath =
328325
binPath + ".old-" + Math.random().toString(36).substring(8);
329326
this.output.info(
330-
`Moving existing binary to ${path.basename(oldBinPath)}`,
327+
"Moving existing binary to",
328+
path.basename(oldBinPath),
331329
);
332330
await fs.rename(binPath, oldBinPath);
333331
}
334332

335333
// Then move the temporary binary into the right place.
336-
this.output.info(`Moving downloaded file to ${path.basename(binPath)}`);
334+
this.output.info("Moving downloaded file to", path.basename(binPath));
337335
await fs.mkdir(path.dirname(binPath), { recursive: true });
338336
await fs.rename(tempFile, binPath);
339337

340338
// For debugging, to see if the binary only partially downloaded.
341339
const newStat = await cli.stat(binPath);
342340
this.output.info(
343-
`Downloaded binary size is ${prettyBytes(newStat?.size || 0)}`,
341+
"Downloaded binary size is",
342+
prettyBytes(newStat?.size || 0),
344343
);
345344

346345
// Make sure we can execute this new binary.
347346
const version = await cli.version(binPath);
348-
this.output.info(`Downloaded binary version is ${version}`);
347+
this.output.info("Downloaded binary version is", version);
349348

350349
return binPath;
351350
}

0 commit comments

Comments
 (0)