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

Incorrect TerminalShellExecution exit code #237517

Open
njiang747 opened this issue Jan 8, 2025 · 1 comment
Open

Incorrect TerminalShellExecution exit code #237517

njiang747 opened this issue Jan 8, 2025 · 1 comment
Assignees

Comments

@njiang747
Copy link

njiang747 commented Jan 8, 2025

Does this issue occur when all extensions are disabled?: Yes/No

  • VS Code Version: 1.94.0
  • OS Version: macOS Sonoma 14.4

Steps to Reproduce:

  1. Listen for onDidEndTerminalShellExecution events
  2. Run a command that returns some exit code
  3. Type the same command and interrupt with ^C (i.e. interrupt without actually running the command)
  4. The exit code reported by the TerminalShellExecution event for the second execution (expected to be undefined since the command didn't actually run) will be the same as the previous command's exit code

For example:

$ echo test^C
-> exit code undefined
$ echo test
-> exit code 0
$ echo test^C
-> exit code 0
$ echo test^C
-> exit code 0
$ echo not test^C
-> exit code undefined
$ echo test^C
-> exit code undefined

From a quick look, this seems like caused by this code (marked as a hack):

// HACK: Handle a special case on some versions of bash where identical commands get merged
// in the output of `history`, this detects that case and sets the exit code to the the last
// command's exit code. This covered the majority of cases but will fail if the same command
// runs with a different exit code, that will need a more robust fix where we send the
// command ID and exit code over to the capability to adjust there.
if (exitCode === undefined) {
const lastCommand = this.commands.length > 0 ? this.commands[this.commands.length - 1] : undefined;
if (this._currentCommand.command && this._currentCommand.command.length > 0 && lastCommand?.command === this._currentCommand.command) {
exitCode = lastCommand.exitCode;
}
}

Copy link

Thanks for creating this issue! It looks like you may be using an old version of VS Code, the latest stable release is 1.96.2. Please try upgrading to the latest version and checking whether this issue remains.

Happy Coding!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants