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

Closed
njiang747 opened this issue Dec 23, 2024 · 3 comments
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!

@meganrogge
Copy link
Contributor

Thanks for the issue. I'd suggest checking if the cwd exists before creating the terminal. IMO, we're doing what's expected already.

@meganrogge meganrogge closed this as not planned Won't fix, can't repro, duplicate, stale Jan 7, 2025
@njiang747
Copy link
Author

@meganrogge This seems a bit unexpected given createTerminal already throws an exception when it can't start a new process

@throws When running in an environment where a new process cannot be started.

I feel like returning a Terminal object that doesn't correspond to an actual terminal and has weird behavior (never resolved Thenable) seems worse than throwing an exception in this case too. Also even if you check that cwd exists, there can always be a race where it's deleted before the terminal is created.

Regardless, what's the best way of checking from an extension that the folder exists (on a potentially remote host)?

Thanks!

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