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

Running 'node' on Windows can show unhelpful error #577

Open
charlespierce opened this issue Oct 18, 2019 · 2 comments
Open

Running 'node' on Windows can show unhelpful error #577

charlespierce opened this issue Oct 18, 2019 · 2 comments

Comments

@charlespierce
Copy link
Contributor

If you don't have a default Node selected and have no Node available elsewhere on the system, running node on Windows results in the error message:

'node' is not recognized as an internal or external command, operable program or batch file

I believe this is the result of the passthrough calling node with the non-Volta path. On Unix, calling a non-existent command results in the call to Command::status returning an Err. On Windows, it results in an Ok with a status code of 1. If possible, we should detect this situation and show the Volta error.

One possibility would be to use which to see if there is something on the system path named node and only pass through if that succeeds.

@charlespierce
Copy link
Contributor Author

Thinking more, this may be a combination of the passthrough command and the fact that on Windows we currently always use cmd.exe /C <command> when executing a Command. For passthrough cases, it may be better to create a direct command.

@charlespierce
Copy link
Contributor Author

Further investigation reveals the above solution won't work. Apparently by default, Windows uses the PATH from the parent process (in this case the Volta shim) to look up an executable when using std::process::Command (see rust-lang/rust#15149). In order to combat that, if you set a PATH environment variable, Rust internally does a lookup to try to find the executable on the new PATH, and if it does find it then it uses it directly (see https://github.com/rust-lang/rust/blob/master/src/libstd/sys/windows/process.rs#L133-L149).

However, in the case of passing through to a node that doesn't exist, Rust looks for node and doesn't find it, so defaults to Windows' normal behavior, which uses the Volta shim's PATH to find node, meaning it finds the shim itself again, and again, and again, until the OS breaks the chain of nested calls. When we use cmd.exe /C <command>, we get an extra layer that makes the PATHs work out, but we run into the error message issues.

To properly support passthrough with correct PATH semantics and good error messages, we may need to create our own windows Command wrapper that provides a similar layer as calling cmd.exe, but also provides a method for informing the top-level Volta process of it's inability to locate a command.

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

No branches or pull requests

2 participants