@@ -29,14 +29,16 @@ import {
29
29
DotnetCompletedGlobalInstallerExecution ,
30
30
DotnetFakeSDKEnvironmentVariableTriggered ,
31
31
SuppressedAcquisitionError ,
32
+ EventBasedError ,
33
+ EventCancellationError ,
32
34
} from '../EventStream/EventStreamEvents' ;
33
35
34
36
import { GlobalInstallerResolver } from './GlobalInstallerResolver' ;
35
37
import { WinMacGlobalInstaller } from './WinMacGlobalInstaller' ;
36
38
import { LinuxGlobalInstaller } from './LinuxGlobalInstaller' ;
37
39
import { TelemetryUtilities } from '../EventStream/TelemetryUtilities' ;
38
40
import { Debugging } from '../Utils/Debugging' ;
39
- import { IDotnetAcquireContext } from '../IDotnetAcquireContext' ;
41
+ import { DotnetInstallType , IDotnetAcquireContext } from '../IDotnetAcquireContext' ;
40
42
import { IGlobalInstaller } from './IGlobalInstaller' ;
41
43
import { IVSCodeExtensionContext } from '../IVSCodeExtensionContext' ;
42
44
import { IUtilityContext } from '../Utils/IUtilityContext' ;
@@ -128,7 +130,7 @@ export class DotnetCoreAcquisitionWorker implements IDotnetCoreAcquisitionWorker
128
130
*/
129
131
public async acquireStatus ( version : string , installMode : DotnetInstallMode , architecture ? : string ) : Promise < IDotnetAcquireResult | undefined >
130
132
{
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 ( ) )
132
134
133
135
const existingAcquisitionPromise = this . installTracker . getPromise ( install ) ;
134
136
if ( existingAcquisitionPromise )
@@ -176,14 +178,14 @@ export class DotnetCoreAcquisitionWorker implements IDotnetCoreAcquisitionWorker
176
178
private async acquire ( version : string , mode : DotnetInstallMode ,
177
179
globalInstallerResolver : GlobalInstallerResolver | null = null , localInvoker ? : IAcquisitionInvoker ) : Promise < IDotnetAcquireResult >
178
180
{
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 ( ) ) ;
180
182
181
183
// Allow for the architecture to be null, which is a legacy behavior.
182
184
if ( this . context . acquisitionContext ?. architecture === null && this . context . acquisitionContext ?. architecture !== undefined )
183
185
{
184
186
install =
185
187
{
186
- installKey : DotnetCoreAcquisitionWorker . getInstallKeyCustomArchitecture ( version , null , globalInstallerResolver !== null ) ,
188
+ installKey : DotnetCoreAcquisitionWorker . getInstallKeyCustomArchitecture ( version , null , globalInstallerResolver !== null ? 'global' : 'local' ) ,
187
189
version : install . version ,
188
190
isGlobal : install . isGlobal ,
189
191
installMode : mode ,
@@ -208,20 +210,20 @@ export class DotnetCoreAcquisitionWorker implements IDotnetCoreAcquisitionWorker
208
210
{
209
211
Debugging . log ( `The Acquisition Worker has Determined a Global Install was requested.` , this . context . eventStream ) ;
210
212
211
- acquisitionPromise = this . acquireGlobalCore ( globalInstallerResolver , install ) . catch ( async ( error : Error ) => {
213
+ acquisitionPromise = this . acquireGlobalCore ( globalInstallerResolver , install ) . catch ( async ( error : any ) =>
214
+ {
212
215
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 ;
215
218
} ) ;
216
219
}
217
220
else
218
221
{
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
+ {
222
224
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 ;
225
227
} ) ;
226
228
}
227
229
@@ -232,22 +234,23 @@ export class DotnetCoreAcquisitionWorker implements IDotnetCoreAcquisitionWorker
232
234
}
233
235
}
234
236
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
236
239
{
237
240
if ( ! architecture )
238
241
{
239
242
// Use the legacy method (no architecture) of installs
240
- return isGlobal ? `${ version } -global` : version ;
243
+ return installType === 'global' ? `${ version } -global` : version ;
241
244
}
242
245
else
243
246
{
244
- return isGlobal ? `${ version } -global~${ architecture } ` : `${ version } ~${ architecture } ` ;
247
+ return installType === 'global' ? `${ version } -global~${ architecture } ` : `${ version } ~${ architecture } ` ;
245
248
}
246
249
}
247
250
248
251
public getInstallKey ( version : string ) : string
249
252
{
250
- return DotnetCoreAcquisitionWorker . getInstallKeyCustomArchitecture ( version , this . installingArchitecture , this . globalResolver !== null ) ;
253
+ return DotnetCoreAcquisitionWorker . getInstallKeyCustomArchitecture ( version , this . installingArchitecture , this . globalResolver !== null ? 'global' : 'local' ) ;
251
254
}
252
255
253
256
/**
@@ -296,11 +299,13 @@ export class DotnetCoreAcquisitionWorker implements IDotnetCoreAcquisitionWorker
296
299
timeoutSeconds : this . context . timeoutSeconds ,
297
300
installRuntime : mode === 'runtime' ,
298
301
installMode : mode ,
302
+ installType : this . context . acquisitionContext ?. installType ?? 'local' , // Before this API param existed, all calls were for local types.
299
303
architecture : this . installingArchitecture
300
304
} as IDotnetInstallationContext ;
301
305
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.
304
309
} ) ;
305
310
this . context . installationValidator . validateDotnetInstall ( install , dotnetPath ) ;
306
311
@@ -345,6 +350,20 @@ export class DotnetCoreAcquisitionWorker implements IDotnetCoreAcquisitionWorker
345
350
return os . arch ( ) ;
346
351
}
347
352
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
+
348
367
private async acquireGlobalCore ( globalInstallerResolver : GlobalInstallerResolver , install : DotnetInstall ) : Promise < string >
349
368
{
350
369
const installingVersion = await globalInstallerResolver . getFullySpecifiedVersion ( ) ;
@@ -371,7 +390,8 @@ export class DotnetCoreAcquisitionWorker implements IDotnetCoreAcquisitionWorker
371
390
372
391
if ( installerResult !== '0' )
373
392
{
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 ) ;
375
395
this . context . eventStream . post ( err ) ;
376
396
throw err ;
377
397
}
0 commit comments