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

Unexpected behavior when calling vscode.window.createTerminal with a non-existent cwd #236869

Open
njiang747 opened this issue Dec 23, 2024 · 1 comment
Assignees

Comments

@njiang747
Copy link

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

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

Steps to Reproduce:

  1. Create a terminal with an nonexistent cwd
  2. Log the returned terminal object
terminal = vscode.window.createTerminal({cwd: '/does/not/exist'});
console.log(terminal);

When creating a terminal with a nonexistent cwd (i.e. a directory that does not exist), the call to createTerminal will not throw an exception even though the terminal will fail to start. The user will see an error notification that says "The terminal process failed to launch: Starting directory (cwd) "/does/not/exist" does not exist.". The call will return a vscode.Terminal object that is not differentiable from a successfully created terminal. Awaiting terminal.processId will block indefinitely.

Overall this seems like unexpected behavior and prone to causing issues in extensions that integrate with the terminal. To get around this, I created a promise that resolves / rejects when vscode.window.onDidCloseTerminal triggers with the returned terminal and await Promise.race between this and the terminal's process ID. This seems to work but is very hacky and I'm not even sure if this consistently works (is it possible for the event to trigger after the call to createTerminal returns before I'm able to register the listener?).

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

2 participants