Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why a mismatch between errno 34 and code ENOENT

Tags:

node.js

posix

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?

like image 421
Peter Lyons Avatar asked Feb 13 '12 00:02

Peter Lyons


2 Answers

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.

like image 134
fnl Avatar answered Sep 20 '22 07:09

fnl


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'

like image 23
deyhle Avatar answered Sep 20 '22 07:09

deyhle