From d57a31f3c8da24331a17f1e678a96d67f303aadb Mon Sep 17 00:00:00 2001 From: Noah Gilson Date: Tue, 20 Aug 2024 15:34:04 -0700 Subject: [PATCH] Handle .NET Failed: Undefined (#1930) Rejecting a promise with a rejected promise as a return value from a function does not reject with the object the inner promise rejected with. Instead it rejects with an undefined value. This means if the SDK installer fails or we fail to elevate, that counts as .NET Install failed: undefined. This fixes this. It also adds a check for the string error as this seems to happen sometimes if the password prompt is rejected. How to test this? Set a break point in win mac global installer on the execute install and edit the command to point to a non existent file. It will then fail and you can see it works now. --- .../src/Utils/CommandExecutor.ts | 18 ++++++++++++------ .../src/Utils/WebRequestWorker.ts | 2 +- vscode-dotnet-runtime.code-workspace | 3 ++- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/vscode-dotnet-runtime-library/src/Utils/CommandExecutor.ts b/vscode-dotnet-runtime-library/src/Utils/CommandExecutor.ts index f51790d3..1954fd32 100644 --- a/vscode-dotnet-runtime-library/src/Utils/CommandExecutor.ts +++ b/vscode-dotnet-runtime-library/src/Utils/CommandExecutor.ts @@ -421,7 +421,7 @@ with options ${JSON.stringify(options)}.`)); this.context?.eventStream.post(new CommandExecutionStdError(`The command ${fullCommandString} encountered ERROR: ${JSON.stringify(error)}`)); } - return resolve({ status: error ? error.code : '0', stderr: execStderr, stdout: execStdout} as CommandExecutorResult); + return resolve({ status: error?.code ? error.code : '0', stderr: execStderr, stdout: execStdout} as CommandExecutorResult); }); }); } @@ -477,25 +477,31 @@ ${commandResult.stdout}`)); ${commandResult.stderr}`)); } - private parseVSCodeSudoExecError(error : any, fullCommandString : string) + private parseVSCodeSudoExecError(error : any, fullCommandString : string) : Error { - if(error.code === 126) + // 'permission' comes from an unlocalized string: https://github.com/bpasero/sudo-prompt/blob/21d9308edcf970f0a9ee0580c539b1457b3dc45b/index.js#L678 + // if you reject on the password prompt on windows before SDK window pops up, no code will be set, so we need to check for this string. + if(error?.code === 126 || (error?.message as string)?.includes('permission')) { const cancelledErr = new CommandExecutionUserRejectedPasswordRequest(new EventCancellationError('CommandExecutionUserRejectedPasswordRequest', `Cancelling .NET Install, as command ${fullCommandString} failed. The user refused the password prompt.`), getInstallFromContext(this.context)); this.context?.eventStream.post(cancelledErr); - return Promise.reject(cancelledErr.error); + return cancelledErr.error; } - else if(error.code === 111777) + else if(error?.code === 111777) { const securityErr = new CommandExecutionUnknownCommandExecutionAttempt(new EventCancellationError('CommandExecutionUnknownCommandExecutionAttempt', `Cancelling .NET Install, as command ${fullCommandString} is UNKNOWN. Please report this at https://github.com/dotnet/vscode-dotnet-runtime/issues.`), getInstallFromContext(this.context)); this.context?.eventStream.post(securityErr); - return Promise.reject(securityErr.error); + return securityErr.error; + } + else + { + return error; } } diff --git a/vscode-dotnet-runtime-library/src/Utils/WebRequestWorker.ts b/vscode-dotnet-runtime-library/src/Utils/WebRequestWorker.ts index b72a8fd5..e7338a8f 100644 --- a/vscode-dotnet-runtime-library/src/Utils/WebRequestWorker.ts +++ b/vscode-dotnet-runtime-library/src/Utils/WebRequestWorker.ts @@ -225,7 +225,7 @@ export class WebRequestWorker } catch(error : any) { - if(error && error?.message && (error?.message as string)?.includes('ENOSPC')) + if(error?.message && (error?.message as string)?.includes('ENOSPC')) { const err = new DiskIsFullError(new EventBasedError('DiskIsFullError', `You don't have enough space left on your disk to install the .NET SDK. Please clean up some space.`), getInstallFromContext(this.context)); diff --git a/vscode-dotnet-runtime.code-workspace b/vscode-dotnet-runtime.code-workspace index 2942fb4c..52cedfbe 100644 --- a/vscode-dotnet-runtime.code-workspace +++ b/vscode-dotnet-runtime.code-workspace @@ -16,7 +16,8 @@ "settings": { "cSpell.words": [ "DOTNETINSTALLMODELIST", - "Republisher" + "Republisher", + "unlocalized" ] } } \ No newline at end of file