@@ -14,7 +14,7 @@ const MAX_URLS = 10;
1414
1515export class Storage {
1616 constructor (
17- private readonly output : vscode . OutputChannel ,
17+ private readonly output : vscode . LogOutputChannel ,
1818 private readonly memento : vscode . Memento ,
1919 private readonly secrets : vscode . SecretStorage ,
2020 private readonly globalStorageUri : vscode . Uri ,
@@ -129,55 +129,52 @@ export class Storage {
129129 const enableDownloads =
130130 vscode . workspace . getConfiguration ( ) . get ( "coder.enableDownloads" ) !==
131131 false ;
132- this . output . appendLine (
132+ this . output . info (
133133 `Downloads are ${ enableDownloads ? "enabled" : "disabled" } ` ,
134134 ) ;
135135
136136 // Get the build info to compare with the existing binary version, if any,
137137 // and to log for debugging.
138138 const buildInfo = await restClient . getBuildInfo ( ) ;
139- this . output . appendLine ( `Got server version: ${ buildInfo . version } ` ) ;
139+ this . output . info ( `Got server version: ${ buildInfo . version } ` ) ;
140140
141141 // Check if there is an existing binary and whether it looks valid. If it
142142 // is valid and matches the server, or if it does not match the server but
143143 // downloads are disabled, we can return early.
144144 const binPath = path . join ( this . getBinaryCachePath ( label ) , cli . name ( ) ) ;
145- this . output . appendLine ( `Using binary path: ${ binPath } ` ) ;
145+ this . output . info ( `Using binary path: ${ binPath } ` ) ;
146146 const stat = await cli . stat ( binPath ) ;
147147 if ( stat === undefined ) {
148- this . output . appendLine ( "No existing binary found, starting download" ) ;
148+ this . output . info ( "No existing binary found, starting download" ) ;
149149 } else {
150- this . output . appendLine (
151- `Existing binary size is ${ prettyBytes ( stat . size ) } ` ,
152- ) ;
150+ this . output . info ( `Existing binary size is ${ prettyBytes ( stat . size ) } ` ) ;
153151 try {
154152 const version = await cli . version ( binPath ) ;
155- this . output . appendLine ( `Existing binary version is ${ version } ` ) ;
153+ this . output . info ( `Existing binary version is ${ version } ` ) ;
156154 // If we have the right version we can avoid the request entirely.
157155 if ( version === buildInfo . version ) {
158- this . output . appendLine (
156+ this . output . info (
159157 "Using existing binary since it matches the server version" ,
160158 ) ;
161159 return binPath ;
162160 } else if ( ! enableDownloads ) {
163- this . output . appendLine (
161+ this . output . info (
164162 "Using existing binary even though it does not match the server version because downloads are disabled" ,
165163 ) ;
166164 return binPath ;
167165 }
168- this . output . appendLine (
166+ this . output . info (
169167 "Downloading since existing binary does not match the server version" ,
170168 ) ;
171169 } catch ( error ) {
172- this . output . appendLine (
173- `Unable to get version of existing binary: ${ error } ` ,
170+ this . output . error (
171+ `Unable to get version of existing binary: ${ error } . Downloading new binary instead ` ,
174172 ) ;
175- this . output . appendLine ( "Downloading new binary instead" ) ;
176173 }
177174 }
178175
179176 if ( ! enableDownloads ) {
180- this . output . appendLine (
177+ this . output . error (
181178 "Unable to download CLI because downloads are disabled" ,
182179 ) ;
183180 throw new Error ( "Unable to download CLI because downloads are disabled" ) ;
@@ -187,9 +184,9 @@ export class Storage {
187184 const removed = await cli . rmOld ( binPath ) ;
188185 removed . forEach ( ( { fileName, error } ) => {
189186 if ( error ) {
190- this . output . appendLine ( `Failed to remove ${ fileName } : ${ error } ` ) ;
187+ this . output . error ( `Failed to remove ${ fileName } : ${ error } ` ) ;
191188 } else {
192- this . output . appendLine ( `Removed ${ fileName } ` ) ;
189+ this . output . info ( `Removed ${ fileName } ` ) ;
193190 }
194191 } ) ;
195192
@@ -202,12 +199,12 @@ export class Storage {
202199 configSource && String ( configSource ) . trim ( ) . length > 0
203200 ? String ( configSource )
204201 : "/bin/" + binName ;
205- this . output . appendLine ( `Downloading binary from: ${ binSource } ` ) ;
202+ this . output . info ( `Downloading binary from: ${ binSource } ` ) ;
206203
207204 // Ideally we already caught that this was the right version and returned
208205 // early, but just in case set the ETag.
209206 const etag = stat !== undefined ? await cli . eTag ( binPath ) : "" ;
210- this . output . appendLine ( `Using ETag: ${ etag } ` ) ;
207+ this . output . info ( `Using ETag: ${ etag } ` ) ;
211208
212209 // Make the download request.
213210 const controller = new AbortController ( ) ;
@@ -223,20 +220,18 @@ export class Storage {
223220 // Ignore all errors so we can catch a 404!
224221 validateStatus : ( ) => true ,
225222 } ) ;
226- this . output . appendLine ( `Got status code ${ resp . status } ` ) ;
223+ this . output . info ( `Got status code ${ resp . status } ` ) ;
227224
228225 switch ( resp . status ) {
229226 case 200 : {
230227 const rawContentLength = resp . headers [ "content-length" ] ;
231228 const contentLength = Number . parseInt ( rawContentLength ) ;
232229 if ( Number . isNaN ( contentLength ) ) {
233- this . output . appendLine (
230+ this . output . error (
234231 `Got invalid or missing content length: ${ rawContentLength } ` ,
235232 ) ;
236233 } else {
237- this . output . appendLine (
238- `Got content length: ${ prettyBytes ( contentLength ) } ` ,
239- ) ;
234+ this . output . info ( `Got content length: ${ prettyBytes ( contentLength ) } ` ) ;
240235 }
241236
242237 // Download to a temporary file.
@@ -317,11 +312,11 @@ export class Storage {
317312 // False means the user canceled, although in practice it appears we
318313 // would not get this far because VS Code already throws on cancelation.
319314 if ( ! completed ) {
320- this . output . appendLine ( "User aborted download" ) ;
315+ this . output . error ( "User aborted download" ) ;
321316 throw new Error ( "User aborted download" ) ;
322317 }
323318
324- this . output . appendLine (
319+ this . output . info (
325320 `Downloaded ${ prettyBytes ( written ) } to ${ path . basename ( tempFile ) } ` ,
326321 ) ;
327322
@@ -331,35 +326,31 @@ export class Storage {
331326 if ( stat !== undefined ) {
332327 const oldBinPath =
333328 binPath + ".old-" + Math . random ( ) . toString ( 36 ) . substring ( 8 ) ;
334- this . output . appendLine (
329+ this . output . info (
335330 `Moving existing binary to ${ path . basename ( oldBinPath ) } ` ,
336331 ) ;
337332 await fs . rename ( binPath , oldBinPath ) ;
338333 }
339334
340335 // Then move the temporary binary into the right place.
341- this . output . appendLine (
342- `Moving downloaded file to ${ path . basename ( binPath ) } ` ,
343- ) ;
336+ this . output . info ( `Moving downloaded file to ${ path . basename ( binPath ) } ` ) ;
344337 await fs . mkdir ( path . dirname ( binPath ) , { recursive : true } ) ;
345338 await fs . rename ( tempFile , binPath ) ;
346339
347340 // For debugging, to see if the binary only partially downloaded.
348341 const newStat = await cli . stat ( binPath ) ;
349- this . output . appendLine (
342+ this . output . info (
350343 `Downloaded binary size is ${ prettyBytes ( newStat ?. size || 0 ) } ` ,
351344 ) ;
352345
353346 // Make sure we can execute this new binary.
354347 const version = await cli . version ( binPath ) ;
355- this . output . appendLine ( `Downloaded binary version is ${ version } ` ) ;
348+ this . output . info ( `Downloaded binary version is ${ version } ` ) ;
356349
357350 return binPath ;
358351 }
359352 case 304 : {
360- this . output . appendLine (
361- "Using existing binary since server returned a 304" ,
362- ) ;
353+ this . output . info ( "Using existing binary since server returned a 304" ) ;
363354 return binPath ;
364355 }
365356 case 404 : {
@@ -508,7 +499,7 @@ export class Storage {
508499 }
509500
510501 public writeToCoderOutputChannel ( message : string ) {
511- this . output . appendLine ( `[ ${ new Date ( ) . toISOString ( ) } ] ${ message } ` ) ;
502+ this . output . info ( message ) ;
512503 // We don't want to focus on the output here, because the
513504 // Coder server is designed to restart gracefully for users
514505 // because of P2P connections, and we don't want to draw
0 commit comments