Skip to content

Commit 9efe2b5

Browse files
Copilotnagilson
andcommitted
Implement cleaner error messages for user-friendly exit codes
Co-authored-by: nagilson <[email protected]>
1 parent 909a7ce commit 9efe2b5

File tree

3 files changed

+63
-4
lines changed

3 files changed

+63
-4
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -455,9 +455,15 @@ To keep your .NET version up to date, please reconnect to the internet at your s
455455

456456
if (installerResult !== '0')
457457
{
458+
// For user-friendly exit codes, show only the interpreted message without verbose details
459+
const interpretedMessage = WinMacGlobalInstaller.InterpretExitCode(installerResult);
460+
const errorMessage = WinMacGlobalInstaller.IsUserFriendlyExitCode(installerResult)
461+
? interpretedMessage
462+
: `An error was raised by the .NET SDK installer. The exit code it gave us: ${installerResult}.
463+
${interpretedMessage}`;
464+
458465
const err = new DotnetNonZeroInstallerExitCodeError(new EventBasedError('DotnetNonZeroInstallerExitCodeError',
459-
`An error was raised by the .NET SDK installer. The exit code it gave us: ${installerResult}.
460-
${WinMacGlobalInstaller.InterpretExitCode(installerResult)}`), install);
466+
errorMessage), install);
461467
context.eventStream.post(err);
462468
throw err;
463469
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,16 @@ We cannot verify our .NET file host at this time. Please try again later or inst
8585
this.registry = registryReader ?? new RegistryReader(context, utilContext);
8686
}
8787

88+
/**
89+
* Determines if the given exit code has a user-friendly, self-contained error message
90+
* that doesn't need additional technical details to be helpful to the user.
91+
*/
92+
public static IsUserFriendlyExitCode(code: string): boolean
93+
{
94+
const userFriendlyExitCodes = ['5', '112', '255', '1618', '2147942405', UNABLE_TO_ACQUIRE_GLOBAL_LOCK_ERR];
95+
return userFriendlyExitCodes.includes(code);
96+
}
97+
8898
public static InterpretExitCode(code: string): string
8999
{
90100
const reportLogMessage = `Please provide your .NET Installer log (note our privacy notice), which can be found at %temp%.

vscode-dotnet-runtime-library/src/test/unit/WinMacGlobalInstaller.test.ts

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,49 @@ ${fs.readdirSync(installerDownloadFolder).join(', ')}`);
223223
shouldNotExistOptionPath = await installer.getExpectedGlobalSDKPath(sdkVersionThatShouldNotExist, os.arch());
224224
assert.equal(shouldNotExistOptionPath, standardHostPath, 'It wont use the emu path if it does not exist');
225225
}
226-
}
227-
}).timeout(standardTimeoutTime);
226+
}
227+
}).timeout(standardTimeoutTime);
228+
229+
test('InterpretExitCode returns user-friendly messages for common exit codes', () =>
230+
{
231+
// Test exit code 5 - insufficient permissions
232+
const exitCode5Message = WinMacGlobalInstaller.InterpretExitCode('5');
233+
assert.equal(exitCode5Message, 'Insufficient permissions are available to install .NET. Please run the installer as an administrator.');
234+
assert.isFalse(exitCode5Message.includes('report'), 'Exit code 5 should not ask for bug reports');
235+
assert.isTrue(WinMacGlobalInstaller.IsUserFriendlyExitCode('5'), 'Exit code 5 should be marked as user-friendly');
236+
237+
// Test exit code 1618 - another installation in progress
238+
const exitCode1618Message = WinMacGlobalInstaller.InterpretExitCode('1618');
239+
assert.equal(exitCode1618Message, 'Another installation is already in progress. Complete that installation before proceeding with this install.');
240+
assert.isFalse(exitCode1618Message.includes('report'), 'Exit code 1618 should not ask for bug reports');
241+
assert.isTrue(WinMacGlobalInstaller.IsUserFriendlyExitCode('1618'), 'Exit code 1618 should be marked as user-friendly');
242+
243+
// Test exit code 112 - disk full
244+
const exitCode112Message = WinMacGlobalInstaller.InterpretExitCode('112');
245+
assert.equal(exitCode112Message, 'The disk is full. Please free up space and try again.');
246+
assert.isFalse(exitCode112Message.includes('report'), 'Exit code 112 should not ask for bug reports');
247+
assert.isTrue(WinMacGlobalInstaller.IsUserFriendlyExitCode('112'), 'Exit code 112 should be marked as user-friendly');
248+
249+
// Test exit code 255 - terminated by another process
250+
const exitCode255Message = WinMacGlobalInstaller.InterpretExitCode('255');
251+
assert.equal(exitCode255Message, 'The .NET Installer was terminated by another process unexpectedly. Please try again.');
252+
assert.isFalse(exitCode255Message.includes('report'), 'Exit code 255 should not ask for bug reports');
253+
assert.isTrue(WinMacGlobalInstaller.IsUserFriendlyExitCode('255'), 'Exit code 255 should be marked as user-friendly');
254+
255+
// Test exit code 2147942405 - insufficient permissions (alternative code)
256+
const exitCode2147942405Message = WinMacGlobalInstaller.InterpretExitCode('2147942405');
257+
assert.equal(exitCode2147942405Message, 'Insufficient permissions are available to install .NET. Please try again as an administrator.');
258+
assert.isFalse(exitCode2147942405Message.includes('report'), 'Exit code 2147942405 should not ask for bug reports');
259+
assert.isTrue(WinMacGlobalInstaller.IsUserFriendlyExitCode('2147942405'), 'Exit code 2147942405 should be marked as user-friendly');
260+
261+
// Test exit code 1 - generic failure (should include report message)
262+
const exitCode1Message = WinMacGlobalInstaller.InterpretExitCode('1');
263+
assert.isTrue(exitCode1Message.includes('report'), 'Exit code 1 should ask for bug reports');
264+
assert.isFalse(WinMacGlobalInstaller.IsUserFriendlyExitCode('1'), 'Exit code 1 should not be marked as user-friendly');
265+
266+
// Test unknown exit code
267+
const unknownCodeMessage = WinMacGlobalInstaller.InterpretExitCode('9999');
268+
assert.equal(unknownCodeMessage, '', 'Unknown exit codes should return empty string');
269+
assert.isFalse(WinMacGlobalInstaller.IsUserFriendlyExitCode('9999'), 'Unknown exit codes should not be marked as user-friendly');
270+
});
228271
});

0 commit comments

Comments
 (0)