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

child_process: spawn incorrect error #45279

Closed
temaivanoff opened this issue Nov 2, 2022 · 3 comments
Closed

child_process: spawn incorrect error #45279

temaivanoff opened this issue Nov 2, 2022 · 3 comments
Labels
child_process Issues and PRs related to the child_process subsystem. libuv Issues and PRs related to the libuv dependency or the uv binding.

Comments

@temaivanoff
Copy link

temaivanoff commented Nov 2, 2022

Version

v18.5.0

Platform

5.4.0-88-generic #99-Ubuntu SMP Thu Sep 23 17:29:00 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

Subsystem

No response

What steps will reproduce the bug?

const spawn = require('child_process').spawn;

const cwd = magicFunction() //  function return failed path: '/tmp1' - when debugging is not immediately visible 
const cp = spawn('ls', [], { cwd });

cp.stdout.on('data', function(data) {
  console.log(data.toString());
 });

cp.stderr.on('data', function(data) {
   console.log(data.toString());
});

cp.on('exit', function(code) {});

How often does it reproduce? Is there a required condition?

No response

What is the expected behavior?

Error: spawn cwd ENOENT

What do you see instead?

Error: spawn ls ENOENT

Additional information

Hi, when calling system commands error is misleading, literally, spawn can't find ls,
actually the problem is in cwd.
It seemed that the problem is with the first argument ls --> /bin/bash and two argument [] --> ['-c', 'ls'] or systems environment OS PATH but not cwd

@Trott Trott added the child_process Issues and PRs related to the child_process subsystem. label Nov 2, 2022
@zhmushan
Copy link
Contributor

I want to know the full content of magicFunction.

@temaivanoff
Copy link
Author

temaivanoff commented Nov 10, 2022

@zhmushan Hello, magic function - it can be anything, but if there is actually no path, then the error does not explicitly say so spawn ls ENOENT it can take a newbie hours to figure out what's going on, so it will be easier spawn cwd ENOENT/spawn options cwd ENOENT/spawn ls, options cwd ENOENT or

HandleError [ERR_INVALID_ARG_ENOENT]: The "options.cwd" property no such file or directory.

for example, I specifically made a mistake in the code in another parameter: argv0

var cp = spawn('ls', [], { argv0: new Buffer([]) });

Uncaught:
TypeError [ERR_INVALID_ARG_TYPE]: The "options.argv0" property must be of type string. Received an instance of Buffer

by mistake everything is clear

@bnoordhuis
Copy link
Member

I can confirm the issue but unfortunately it isn't really fixable.

The chdir() takes place after fork() or posix_spawn(), in the child process. The parent (i.e., node) doesn't really know what went wrong, only that a system call failed with ENOENT but not what system call.

For fork(), the child could perhaps communicate more context to the parent, but with posix_spawn() it's fundamentally unfixable.

Even if the child provided more details, libuv's uv_spawn() function still can't bubble that up to its caller in a backwards compatible manner.

As a libuv maintainer, I'm going to make the judgment call that this issue isn't pressing enough to introduce a new spawn API. Doubly so because the issue would still exist with posix_spawn() and possibly CreateProcess() on Windows.

@bnoordhuis bnoordhuis closed this as not planned Won't fix, can't repro, duplicate, stale Nov 29, 2022
@bnoordhuis bnoordhuis added the libuv Issues and PRs related to the libuv dependency or the uv binding. label Nov 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
child_process Issues and PRs related to the child_process subsystem. libuv Issues and PRs related to the libuv dependency or the uv binding.
Projects
None yet
Development

No branches or pull requests

4 participants