我在Node.js中使用子进程,当我尝试生成一个不存在可执行文件的进程时,spawn会抛出一个错误对象: https://nodejs.org/api/errors.html#errors_class_system_error
将error.errno和error.code设为“ENOENT”,表示“不存在此类文件或目录”
但我需要的意思是“没有这样的文件或目录存在”,这在错误对象中是不可用的 Node.js中是否有一个类可以帮助我。
答案 0 :(得分:1)
将此系统错误代码输入此功能,它将为您提供错误说明。
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";
}
}