Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move TerminalInstance's process exit code message handling into a function and test #136061

Closed
Tracked by #136065
Tyriar opened this issue Oct 28, 2021 · 0 comments
Closed
Tracked by #136065
Assignees
Labels
debt Code quality issues insiders-released Patch has been released in VS Code Insiders terminal Integrated terminal issues
Milestone

Comments

@Tyriar
Copy link
Member

Tyriar commented Oct 28, 2021

Move this into an exported function at the bottom of the file and add tests to cover all cases:

let exitCodeMessage: string | undefined;
// Create exit code message
switch (typeof exitCodeOrError) {
case 'number':
// Only show the error if the exit code is non-zero
this._exitCode = exitCodeOrError;
if (this._exitCode === 0) {
break;
}
let commandLine: string | undefined = undefined;
if (this._shellLaunchConfig.executable) {
commandLine = this._shellLaunchConfig.executable;
if (typeof this._shellLaunchConfig.args === 'string') {
commandLine += ` ${this._shellLaunchConfig.args}`;
} else if (this._shellLaunchConfig.args && this._shellLaunchConfig.args.length) {
commandLine += this._shellLaunchConfig.args.map(a => ` '${a}'`).join();
}
}
if (this._processManager.processState === ProcessState.KilledDuringLaunch) {
if (commandLine) {
exitCodeMessage = nls.localize('launchFailed.exitCodeAndCommandLine', "The terminal process \"{0}\" failed to launch (exit code: {1}).", commandLine, this._exitCode);
break;
}
exitCodeMessage = nls.localize('launchFailed.exitCodeOnly', "The terminal process failed to launch (exit code: {0}).", this._exitCode);
break;
}
if (commandLine) {
exitCodeMessage = nls.localize('terminated.exitCodeAndCommandLine', "The terminal process \"{0}\" terminated with exit code: {1}.", commandLine, this._exitCode);
break;
}
exitCodeMessage = nls.localize('terminated.exitCodeOnly', "The terminal process terminated with exit code: {0}.", this._exitCode);
break;
case 'object':
if (exitCodeOrError.message.toString().includes('Could not find pty with id')) {
break;
}
this._exitCode = exitCodeOrError.code;
const conptyError = exitCodeOrError.message.match(/.*error code:\s*(\d+).*$/);
if (conptyError) {
const errorCode = conptyError.length > 1 ? parseInt(conptyError[1]) : undefined;
switch (errorCode) {
case 5:
exitCodeOrError.message = `Access was denied to the path containing your executable ${this.shellLaunchConfig.executable}. Manage and change your permissions to get this to work.`;
break;
case 267:
exitCodeOrError.message = `Invalid starting directory ${this.initialCwd}, review your terminal.integrated.cwd setting`;
break;
case 1260:
exitCodeOrError.message = `Windows cannot open this program because it has been prevented by a software restriction policy. For more information, open Event Viewer or contact your system Administrator`;
break;
}
}
exitCodeMessage = nls.localize('launchFailed.errorMessage', "The terminal process failed to launch: {0}.", exitCodeOrError.message);
break;
}

@Tyriar Tyriar added debt Code quality issues terminal Integrated terminal issues labels Oct 28, 2021
@Tyriar Tyriar added this to the November 2021 milestone Oct 28, 2021
Tyriar added a commit that referenced this issue Nov 12, 2021
@Tyriar Tyriar closed this as completed in 547da02 Nov 12, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Dec 27, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
debt Code quality issues insiders-released Patch has been released in VS Code Insiders terminal Integrated terminal issues
Projects
None yet
Development

No branches or pull requests

4 participants
@Tyriar @meganrogge and others