All the values in os.constants.errno
are positive, e.g.
{
E2BIG: 7,
EACCES: 13,
EADDRINUSE: 48,
EADDRNOTAVAIL: 49,
EAFNOSUPPORT: 47,
EAGAIN: 35,
EALREADY: 37,
EBADF: 9,
EBADMSG: 94,
// ...
}
Meanwhile, util.getSystemErrorMap
and util.getSystemErrorName
have negative integer codes.
> util.getSystemErrorName(os.constants.errno.E2BIG)
Uncaught:
RangeError [ERR_OUT_OF_RANGE]: The value of "err" is out of range. It must be a negative integer. Received 7
at Object.getSystemErrorName (node:util:343:11) {
code: 'ERR_OUT_OF_RANGE'
}
> util.getSystemErrorName(-os.constants.errno.E2BIG)
'E2BIG'
Node’s documentation on error objects says:
error.errno
<number>
The
error.errno
property is a negative number which corresponds to the error code defined in libuv Error handling.On Windows the error number provided by the system will be normalized by libuv.
To get the string representation of the error code, use
util.getSystemErrorName(error.errno)
.
Which sign is supposed to be considered canonical? What is the purpose of this inconsistency?
1