0

This is what I am doing:

var fork = require('child_process').fork;
var child = fork('some_script');
  child.on('error', function(err) {
         console.log(err);
});

I want to catch the error if the script is not valid. There is an answer posted here which works great for spawn but fails for fork. There is also this answer which helps to debug but does not serve my purpose. I want to log the error as the script is dynamically generated.

    process.on('uncaughtException', function (exception) { ...}

is neither recommended nor will work, I think...

UPDATE: Yes, it is a duplicate. Sorry I missed it. However, I am repeating the comment of RobertKlep here. Now the code is 1 instead of 8 in the cited answer. Thats important to note.

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Sunny
  • 9,245
  • 10
  • 49
  • 79
  • 1
    I have to add that recent versions of Node exit with code 1 instead of 8 as suggested in the answer. – robertklep Jun 09 '16 at 18:24
  • @robertklep Thanks. It is indeed a duplicate. I did not find it in my search for whatever reason. Yes, 1 and not 8 works now. – Sunny Jun 09 '16 at 19:45
  • @robertklep Anyway I can find out the other codes? I do not see it in the docs. – Sunny Jun 09 '16 at 19:52
  • 1
    [See here](https://nodejs.org/api/process.html#process_exit_codes) for a list of error codes for the most recent Node versions. – robertklep Jun 09 '16 at 21:01

0 Answers0