Skip to content

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

Description

@charlespierce

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.

Activity

  1. charlespierce commented on Oct 18, 2019

    @charlespierce
    ContributorAuthor

    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.

  2. charlespierce commented on Oct 18, 2019

    @charlespierce
    ContributorAuthor

    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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions