So if I run this simple call in node.js v0.6.7 on OS X 10.6.8 with a bogus path, I get an error, as expected.
var fs = require("fs");
fs.stat("/tmp/foo", function(error, stat) {
return console.log(error);
});
It prints this output:
{ [Error: ENOENT, no such file or directory '/tmp/foo'] errno: 34, code: 'ENOENT', path: '/tmp/foo' }
My question is, according to /usr/include/sys/errno.h on my system, ENOENT should have code 2, so why is this error saying errno 34 (ERANGE in errno.h), but pairing it with the error message from ENOENT?
node.js translates system errnos to internal "errnos" (see deps/uv/include/uv.h and uv_translate_sys_error in deps/uv/src/unix/error.c or deps/uv/src/win/error.c for a mapping) as to achieve a common representation for error-conditions under Windows and Unix.
34 is the node.js-errno for ENOENT, so everything is alright.
It seems that node.js changed the errno with 0.12.0. ENOENT is -2now.
So it is probably better to check for code === 'ENOENT'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With