Skip to content

Commit 13e2bf6

Browse files
authored
Consider when the user Cancels the SDK Installer on Mac (#1993)
* Try asking the user if the want to continue * Add a message on mac if someone tries to cancel the installation Consider that to tell if the user wanted to say 'no' or 'yes' to retry, that doesnt indicate whether they meant to do the install or not. We would then need more options to tell if we actually failed or not. I dont want to rely on this and I dont think it is a high enough priority with the complexity required to reroute the code to add a retry button that does a certain retry depending on if someone clicked to cancel the install on mac * Consider if the dotnet file doesnt exist but the folder does * Fix bug
1 parent 2282514 commit 13e2bf6

3 files changed

Lines changed: 21 additions & 32 deletions

File tree

vscode-dotnet-runtime-library/src/Acquisition/DotnetCoreAcquisitionWorker.ts

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -505,35 +505,7 @@ ${WinMacGlobalInstaller.InterpretExitCode(installerResult)}`), install);
505505
dotnetPath = await installer.getExpectedGlobalSDKPath(installingVersion,
506506
context.acquisitionContext.architecture ?? this.getDefaultInternalArchitecture(context.acquisitionContext.architecture));
507507

508-
try
509-
{
510-
context.installationValidator.validateDotnetInstall(install, dotnetPath, os.platform() !== 'win32');
511-
}
512-
catch(error : any)
513-
{
514-
if(os.platform() === 'darwin')
515-
{
516-
const executor = new CommandExecutor(context, this.utilityContext);
517-
const result = await executor.execute(CommandExecutor.makeCommand('which', ['dotnet']));
518-
if(result?.status === '0')
519-
{
520-
context.eventStream.post(new DotnetInstallationValidated(install));
521-
dotnetPath = result.stdout;
522-
}
523-
else
524-
{
525-
// Remove this when https://github.com/typescript-eslint/typescript-eslint/issues/2728 is done
526-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
527-
error.message ??= 'The .NET SDK installer did not install the SDK correctly.';
528-
// Remove this when https://github.com/typescript-eslint/typescript-eslint/issues/2728 is done
529-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
530-
error.message += `Which dotnet returned ${result?.stdout} and ${result?.stderr}.`;
531-
throw error;
532-
}
533-
}
534-
535-
throw error;
536-
}
508+
context.installationValidator.validateDotnetInstall(install, dotnetPath, os.platform() !== 'win32', os.platform() !== 'darwin');
537509

538510
context.eventStream.post(new DotnetAcquisitionCompleted(install, dotnetPath, installingVersion));
539511

vscode-dotnet-runtime-library/src/Acquisition/IInstallationValidator.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* The .NET Foundation licenses this file to you under the MIT license.
44
*--------------------------------------------------------------------------------------------*/
55

6+
import { IDotnetAcquireContext, IVSCodeExtensionContext } from '..';
67
import { IEventStream } from '../EventStream/EventStream';
78
import { DotnetInstall } from './DotnetInstall';
89

vscode-dotnet-runtime-library/src/Acquisition/InstallationValidator.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*--------------------------------------------------------------------------------------------*/
55
import * as fs from 'fs';
66
import * as path from 'path';
7+
import * as os from 'os';
78
import {
89
DotnetInstallationValidated,
910
DotnetInstallationValidationError,
@@ -34,8 +35,16 @@ export class InstallationValidator extends IInstallationValidator {
3435
this.assertOrThrowError(failOnErr, fs.existsSync(folder),
3536
`${dotnetValidationFailed} Expected dotnet folder ${dotnetPath} does not exist.`, install, dotnetPath);
3637

37-
this.assertOrThrowError(failOnErr, fs.readdirSync(folder).length !== 0,
38-
`${dotnetValidationFailed} The dotnet folder is empty "${dotnetPath}"`, install, dotnetPath);
38+
try
39+
{
40+
this.assertOrThrowError(failOnErr, fs.readdirSync(folder).length !== 0,
41+
`${dotnetValidationFailed} The dotnet folder is empty "${dotnetPath}"`, install, dotnetPath);
42+
}
43+
catch(error : any) // fs.readdirsync throws ENOENT so we need to recall the function
44+
{
45+
this.assertOrThrowError(failOnErr, false,
46+
`${dotnetValidationFailed} The dotnet file dne "${dotnetPath}"`, install, dotnetPath);
47+
}
3948
}
4049

4150
this.eventStream.post(new DotnetInstallationValidated(install));
@@ -47,7 +56,14 @@ export class InstallationValidator extends IInstallationValidator {
4756
this.eventStream.post(new DotnetInstallationValidationError(new Error(message), install, dotnetPath));
4857
throw new EventBasedError('DotnetInstallationValidationError', message);
4958
}
50-
else if(!passedValidation)
59+
60+
if(os.platform() === 'darwin')
61+
{
62+
message = `Did you close the .NET Installer, cancel the installation, or refuse the password prompt? If you want to install the .NET SDK, please try again. If you are facing an error, please report it at https://github.com/dotnet/vscode-dotnet-runtime/issues.
63+
${message}`;
64+
}
65+
66+
if(!passedValidation && !failOnErr)
5167
{
5268
this.eventStream?.post(new DotnetInstallationValidationMissed(new Error(message), message))
5369
}

0 commit comments

Comments
 (0)