Skip to content

Commit

Permalink
Consider when the user Cancels the SDK Installer on Mac (#1993)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
nagilson authored Oct 16, 2024
1 parent 2282514 commit 13e2bf6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -505,35 +505,7 @@ ${WinMacGlobalInstaller.InterpretExitCode(installerResult)}`), install);
dotnetPath = await installer.getExpectedGlobalSDKPath(installingVersion,
context.acquisitionContext.architecture ?? this.getDefaultInternalArchitecture(context.acquisitionContext.architecture));

try
{
context.installationValidator.validateDotnetInstall(install, dotnetPath, os.platform() !== 'win32');
}
catch(error : any)
{
if(os.platform() === 'darwin')
{
const executor = new CommandExecutor(context, this.utilityContext);
const result = await executor.execute(CommandExecutor.makeCommand('which', ['dotnet']));
if(result?.status === '0')
{
context.eventStream.post(new DotnetInstallationValidated(install));
dotnetPath = result.stdout;
}
else
{
// Remove this when https://github.com/typescript-eslint/typescript-eslint/issues/2728 is done
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
error.message ??= 'The .NET SDK installer did not install the SDK correctly.';
// Remove this when https://github.com/typescript-eslint/typescript-eslint/issues/2728 is done
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
error.message += `Which dotnet returned ${result?.stdout} and ${result?.stderr}.`;
throw error;
}
}

throw error;
}
context.installationValidator.validateDotnetInstall(install, dotnetPath, os.platform() !== 'win32', os.platform() !== 'darwin');

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* The .NET Foundation licenses this file to you under the MIT license.
*--------------------------------------------------------------------------------------------*/

import { IDotnetAcquireContext, IVSCodeExtensionContext } from '..';
import { IEventStream } from '../EventStream/EventStream';
import { DotnetInstall } from './DotnetInstall';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import * as fs from 'fs';
import * as path from 'path';
import * as os from 'os';
import {
DotnetInstallationValidated,
DotnetInstallationValidationError,
Expand Down Expand Up @@ -34,8 +35,16 @@ export class InstallationValidator extends IInstallationValidator {
this.assertOrThrowError(failOnErr, fs.existsSync(folder),
`${dotnetValidationFailed} Expected dotnet folder ${dotnetPath} does not exist.`, install, dotnetPath);

this.assertOrThrowError(failOnErr, fs.readdirSync(folder).length !== 0,
`${dotnetValidationFailed} The dotnet folder is empty "${dotnetPath}"`, install, dotnetPath);
try
{
this.assertOrThrowError(failOnErr, fs.readdirSync(folder).length !== 0,
`${dotnetValidationFailed} The dotnet folder is empty "${dotnetPath}"`, install, dotnetPath);
}
catch(error : any) // fs.readdirsync throws ENOENT so we need to recall the function
{
this.assertOrThrowError(failOnErr, false,
`${dotnetValidationFailed} The dotnet file dne "${dotnetPath}"`, install, dotnetPath);
}
}

this.eventStream.post(new DotnetInstallationValidated(install));
Expand All @@ -47,7 +56,14 @@ export class InstallationValidator extends IInstallationValidator {
this.eventStream.post(new DotnetInstallationValidationError(new Error(message), install, dotnetPath));
throw new EventBasedError('DotnetInstallationValidationError', message);
}
else if(!passedValidation)

if(os.platform() === 'darwin')
{
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.
${message}`;
}

if(!passedValidation && !failOnErr)
{
this.eventStream?.post(new DotnetInstallationValidationMissed(new Error(message), message))
}
Expand Down

0 comments on commit 13e2bf6

Please sign in to comment.