X Tutup
The Wayback Machine - https://web.archive.org/web/20231224201348/https://github.com/nodejs/node/issues/39916
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

support people to custom logic to handle the exit code when using the execSync API #39916

Open
Zheaoli opened this issue Aug 27, 2021 · 1 comment
Labels
child_process Issues and PRs related to the child_process subsystem.

Comments

@Zheaoli
Copy link

Zheaoli commented Aug 27, 2021

Is your feature request related to a problem? Please describe.
Please describe the problem you are trying to solve.

I find out this error, here's the detail

CleanShot 2021-08-28 at 00 32 31@2x

When I want run ps -Af | grep -q -E -c "\\-\\-user-data-dir=\\.+App" by using the execSync API, I got some error. I have found out this root cause, that the checkExecSyncError has checked the child process's exit code is 0 or not. If it is not 0, the checkExecSyncError will raise a new exception.

function checkExecSyncError(ret, args, cmd) {
  let err;
  if (ret.error) {
    err = ret.error;
  } else if (ret.status !== 0) {
    let msg = 'Command failed: ';
    msg += cmd || ArrayPrototypeJoin(args, ' ');
    if (ret.stderr && ret.stderr.length > 0)
      msg += `\n${ret.stderr.toString()}`;
    // eslint-disable-next-line no-restricted-syntax
    err = new Error(msg);
  }
  if (err) {
    ObjectAssign(err, ret);
  }
  return err;
}

But here's the problem, in the POSIX specification(aka IEEE Std 1003), the people define the EXIT Code 1 represents all the general errors, so some of the software such as grep's developer use 1 to represent the software logic error( In grep, exit code 1 means that there's anything has been matched. FYI https://linux.die.net/man/1/grep).

In another circumstance, the POSIX(such as GNU/Linux, FreeBSD) allows people to use the custom exit code out of 0-255 to represent the software's own custom login error.

Above this, in my personal opinion, I think the Node.js developer needs a way to handle the child process exit code manually. We can allow people to add some callback to get the origin status code, the stdout content, the stderr content, or something else.

If you people are interested about this feature request, I'm very glad to comment my design proposal.

@mscdex
Copy link
Contributor

mscdex commented Aug 27, 2021

Why not just use spawnSync() with { shell: true } instead? That way you can handle the exit code however you like.

@Mesteery Mesteery added the child_process Issues and PRs related to the child_process subsystem. label Aug 28, 2021
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.
Projects
None yet
Development

No branches or pull requests

3 participants
X Tutup