@@ -29,14 +29,16 @@ import {
2929 DotnetCompletedGlobalInstallerExecution ,
3030 DotnetFakeSDKEnvironmentVariableTriggered ,
3131 SuppressedAcquisitionError ,
32+ EventBasedError ,
33+ EventCancellationError ,
3234} from '../EventStream/EventStreamEvents' ;
3335
3436import { GlobalInstallerResolver } from './GlobalInstallerResolver' ;
3537import { WinMacGlobalInstaller } from './WinMacGlobalInstaller' ;
3638import { LinuxGlobalInstaller } from './LinuxGlobalInstaller' ;
3739import { TelemetryUtilities } from '../EventStream/TelemetryUtilities' ;
3840import { Debugging } from '../Utils/Debugging' ;
39- import { IDotnetAcquireContext } from '../IDotnetAcquireContext' ;
41+ import { DotnetInstallType , IDotnetAcquireContext } from '../IDotnetAcquireContext' ;
4042import { IGlobalInstaller } from './IGlobalInstaller' ;
4143import { IVSCodeExtensionContext } from '../IVSCodeExtensionContext' ;
4244import { IUtilityContext } from '../Utils/IUtilityContext' ;
@@ -128,7 +130,7 @@ export class DotnetCoreAcquisitionWorker implements IDotnetCoreAcquisitionWorker
128130 */
129131 public async acquireStatus ( version : string , installMode : DotnetInstallMode , architecture ? : string ) : Promise < IDotnetAcquireResult | undefined >
130132 {
131- const install = GetDotnetInstallInfo ( version , installMode , false , architecture ? architecture : this . installingArchitecture ?? DotnetCoreAcquisitionWorker . defaultArchitecture ( ) )
133+ const install = GetDotnetInstallInfo ( version , installMode , 'local' , architecture ? architecture : this . installingArchitecture ?? DotnetCoreAcquisitionWorker . defaultArchitecture ( ) )
132134
133135 const existingAcquisitionPromise = this . installTracker . getPromise ( install ) ;
134136 if ( existingAcquisitionPromise )
@@ -176,14 +178,14 @@ export class DotnetCoreAcquisitionWorker implements IDotnetCoreAcquisitionWorker
176178 private async acquire ( version : string , mode : DotnetInstallMode ,
177179 globalInstallerResolver : GlobalInstallerResolver | null = null , localInvoker ? : IAcquisitionInvoker ) : Promise < IDotnetAcquireResult >
178180 {
179- let install = GetDotnetInstallInfo ( version , mode , globalInstallerResolver !== null , this . installingArchitecture ?? DotnetCoreAcquisitionWorker . defaultArchitecture ( ) ) ;
181+ let install = GetDotnetInstallInfo ( version , mode , globalInstallerResolver !== null ? 'global' : 'local' , this . installingArchitecture ?? DotnetCoreAcquisitionWorker . defaultArchitecture ( ) ) ;
180182
181183 // Allow for the architecture to be null, which is a legacy behavior.
182184 if ( this . context . acquisitionContext ?. architecture === null && this . context . acquisitionContext ?. architecture !== undefined )
183185 {
184186 install =
185187 {
186- installKey : DotnetCoreAcquisitionWorker . getInstallKeyCustomArchitecture ( version , null , globalInstallerResolver !== null ) ,
188+ installKey : DotnetCoreAcquisitionWorker . getInstallKeyCustomArchitecture ( version , null , globalInstallerResolver !== null ? 'global' : 'local' ) ,
187189 version : install . version ,
188190 isGlobal : install . isGlobal ,
189191 installMode : mode ,
@@ -208,20 +210,20 @@ export class DotnetCoreAcquisitionWorker implements IDotnetCoreAcquisitionWorker
208210 {
209211 Debugging . log ( `The Acquisition Worker has Determined a Global Install was requested.` , this . context . eventStream ) ;
210212
211- acquisitionPromise = this . acquireGlobalCore ( globalInstallerResolver , install ) . catch ( async ( error : Error ) => {
213+ acquisitionPromise = this . acquireGlobalCore ( globalInstallerResolver , install ) . catch ( async ( error : any ) =>
214+ {
212215 await this . installTracker . untrackInstallingVersion ( install ) ;
213- error . message = `.NET Acquisition Failed: ${ error . message } ` ;
214- throw error ;
216+ const err = this . getErrorOrStringAsEventError ( error ) ;
217+ throw err ;
215218 } ) ;
216219 }
217220 else
218221 {
219- Debugging . log ( `The Acquisition Worker has Determined a Local Install was requested.` , this . context . eventStream ) ;
220-
221- acquisitionPromise = this . acquireLocalCore ( version , mode , install , localInvoker ! ) . catch ( async ( error : Error ) => {
222+ acquisitionPromise = this . acquireLocalCore ( version , mode , install , localInvoker ! ) . catch ( async ( error : any ) =>
223+ {
222224 await this . installTracker . untrackInstallingVersion ( install ) ;
223- error . message = `.NET Acquisition Failed: ${ error . message } ` ;
224- throw error ;
225+ const err = this . getErrorOrStringAsEventError ( error ) ;
226+ throw err ;
225227 } ) ;
226228 }
227229
@@ -232,22 +234,23 @@ export class DotnetCoreAcquisitionWorker implements IDotnetCoreAcquisitionWorker
232234 }
233235 }
234236
235- public static getInstallKeyCustomArchitecture ( version : string , architecture : string | null | undefined , isGlobal = false ) : string
237+ public static getInstallKeyCustomArchitecture ( version : string , architecture : string | null | undefined ,
238+ installType : DotnetInstallType = 'local' ) : string
236239 {
237240 if ( ! architecture )
238241 {
239242 // Use the legacy method (no architecture) of installs
240- return isGlobal ? `${ version } -global` : version ;
243+ return installType === 'global' ? `${ version } -global` : version ;
241244 }
242245 else
243246 {
244- return isGlobal ? `${ version } -global~${ architecture } ` : `${ version } ~${ architecture } ` ;
247+ return installType === 'global' ? `${ version } -global~${ architecture } ` : `${ version } ~${ architecture } ` ;
245248 }
246249 }
247250
248251 public getInstallKey ( version : string ) : string
249252 {
250- return DotnetCoreAcquisitionWorker . getInstallKeyCustomArchitecture ( version , this . installingArchitecture , this . globalResolver !== null ) ;
253+ return DotnetCoreAcquisitionWorker . getInstallKeyCustomArchitecture ( version , this . installingArchitecture , this . globalResolver !== null ? 'global' : 'local' ) ;
251254 }
252255
253256 /**
@@ -296,11 +299,13 @@ export class DotnetCoreAcquisitionWorker implements IDotnetCoreAcquisitionWorker
296299 timeoutSeconds : this . context . timeoutSeconds ,
297300 installRuntime : mode === 'runtime' ,
298301 installMode : mode ,
302+ installType : this . context . acquisitionContext ?. installType ?? 'local' , // Before this API param existed, all calls were for local types.
299303 architecture : this . installingArchitecture
300304 } as IDotnetInstallationContext ;
301305 this . context . eventStream . post ( new DotnetAcquisitionStarted ( install , version , this . context . acquisitionContext ?. requestingExtensionId ) ) ;
302- await acquisitionInvoker . installDotnet ( installContext , install ) . catch ( ( reason ) => {
303- throw Error ( `Installation failed: ${ reason } ` ) ;
306+ await acquisitionInvoker . installDotnet ( installContext , install ) . catch ( ( reason ) =>
307+ {
308+ throw reason ; // This will get handled and cast into an event based error by its caller.
304309 } ) ;
305310 this . context . installationValidator . validateDotnetInstall ( install , dotnetPath ) ;
306311
@@ -345,6 +350,20 @@ export class DotnetCoreAcquisitionWorker implements IDotnetCoreAcquisitionWorker
345350 return os . arch ( ) ;
346351 }
347352
353+ private getErrorOrStringAsEventError ( error : any )
354+ {
355+ if ( error instanceof EventBasedError || error instanceof EventCancellationError )
356+ {
357+ error . message = `.NET Acquisition Failed: ${ error . message } ` ;
358+ return error ;
359+ }
360+ else
361+ {
362+ const newError = new EventBasedError ( 'DotnetAcquisitionError' , `.NET Acquisition Failed: ${ error ?. message ?? error } ` ) ;
363+ return newError ;
364+ }
365+ }
366+
348367 private async acquireGlobalCore ( globalInstallerResolver : GlobalInstallerResolver , install : DotnetInstall ) : Promise < string >
349368 {
350369 const installingVersion = await globalInstallerResolver . getFullySpecifiedVersion ( ) ;
@@ -371,7 +390,8 @@ export class DotnetCoreAcquisitionWorker implements IDotnetCoreAcquisitionWorker
371390
372391 if ( installerResult !== '0' )
373392 {
374- const err = new DotnetNonZeroInstallerExitCodeError ( new Error ( `An error was raised by the .NET SDK installer. The exit code it gave us: ${ installerResult } ` ) , install ) ;
393+ const err = new DotnetNonZeroInstallerExitCodeError ( new EventBasedError ( 'DotnetNonZeroInstallerExitCodeError' ,
394+ `An error was raised by the .NET SDK installer. The exit code it gave us: ${ installerResult } ` ) , install ) ;
375395 this . context . eventStream . post ( err ) ;
376396 throw err ;
377397 }
0 commit comments