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() uncatchable error #3523

Closed
doivosevic opened this issue Oct 26, 2015 · 3 comments
Closed

child_process.spawn() uncatchable error #3523

doivosevic opened this issue Oct 26, 2015 · 3 comments

Comments

@doivosevic
Copy link

After calling

try {
    child_process.spawn('kill ' + pid + ';screen -d -m -L node ' + serverjsLocation);
}
catch (e) {
    filelog(e);
}

I get

events.js:141
      throw er; // Unhandled 'error' event
      ^

Error: spawn kill 11088;screen -d -m -L node /home/git/Gitorade/server.js ENOENT
    at exports._errnoException (util.js:874:11)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:178:32)
    at onErrorNT (internal/child_process.js:344:16)
    at doNTCallback2 (node.js:439:9)
    at process._tickCallback (node.js:353:17)

Node version is 4.2.1
I added try block after I started getting this error so that I might debug it.
Is this the proper way to catch this exception?
The docs (https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options) do not mention callback although this is an async function. How so? I went throught nodejs internal code and while I did not get too into it I got a feeling that the function is expected to have a callback.

How do I catch this error?

@fl0w
Copy link

fl0w commented Oct 26, 2015

ChildProcess is an EventEmitter. You'll want to hook/handle error events, specifically you'll want to handle the error event. Have a look.

@newtondev
Copy link

var child = child_process.spawn('kill ' + pid + ';screen -d -m -L node ' + serverjsLocation);
child.on('error', function(function (err) {
console.log('Failed to start child process.');
});

@doivosevic
Copy link
Author

Thanks a lot guys! Should have read the docs more thoroughly..

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

3 participants