1

I am using child process in Node.js and when I try to spawn a process for which executable does not exist the spawn throws a error object : https://nodejs.org/api/errors.html#errors_class_system_error

with error.errno and error.code as "ENOENT" which means "no such files or directory exist"

but I need its meaning that is "no such files or directory exist" which is not available in error object Is there a class in Node.js which can help me with the same.

1 Answer 1

1

Input the system error code into this function and it will give you the description of the error.

function system_error_description(err_code) {
  if(typeof err_code != "string"
      || err_code.length < 2 
      || err_code[0] != "E") {
    return "Invalid system error code '" + err_code.toString() + "'";
  }
  switch(err_code) {
    case "EACCES":
      return "Permission denied";
    case "EADDRINUSE":
      return "Address already in use";
    case "ECONNREFUSED":
      return "Connection refused";
    case "ECONNRESET":
      return "Connection reset by peer";
    case "EEXIST":
      return "File exists";
    case "EISDIR":
      return "Is a directory";
    case "EMFILE":
      return "Too many open files in system";
    case "ENOENT":
      return "No such file or directory";
    case "ENOTDIR":
      return "Not a directory";
    case "EPERM":
      return "Operation not permitted";
    case "EPIPE":
      return "Broken pipe";
    case "ETIMEDOUT":
      return "Operation timed out";
    default:
      return "System error code '" + err_code + "' not recognized";
  }
}
Sign up to request clarification or add additional context in comments.

1 Comment

no other better way ? I mean nodejs does not have any representation for these error descriptions. This was my last resort.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.