diff options
author | Joyee Cheung <joyeec9h3@gmail.com> | 2019-06-09 16:04:51 +0300 |
---|---|---|
committer | Joyee Cheung <joyeec9h3@gmail.com> | 2019-06-17 05:18:09 +0300 |
commit | 1432065e9dc77218507f328b63cb7f5d279dd6e9 (patch) | |
tree | 0f4273124106700d9069281b6588b64a4ccf2b2d /lib/internal/cluster | |
parent | 28d3f1963a98ce157b360c0a3ba70fb8e1f73f60 (diff) |
lib: correct error.errno to always be numeric
Historically `error.errno` of system errors thrown by Node.js
can sometimes be the same as `err.code`, which are string
representations of the error numbers. This is useless and incorrect,
and results in an information loss for users since then they
will have to resort to something like
`process.binding('uv'[`UV_${errno}`])` to get to the numeric
error codes.
This patch corrects this behavior by always setting `error.errno`
to be negative numbers. For fabricated errors like `ENOTFOUND`,
`error.errno` is now undefined since there is no numeric equivalent
for them anyway. For c-ares errors, `error.errno` is now undefined
because the numeric representations (negated) can be in conflict
with libuv error codes - this is fine since numeric codes was
not available for c-ares errors anyway.
Users can use the public API `util.getSystemErrorName(errno)`
to retrieve string codes for these numbers.
PR-URL: https://github.com/nodejs/node/pull/28140
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Diffstat (limited to 'lib/internal/cluster')
-rw-r--r-- | lib/internal/cluster/round_robin_handle.js | 6 |
1 files changed, 1 insertions, 5 deletions
diff --git a/lib/internal/cluster/round_robin_handle.js b/lib/internal/cluster/round_robin_handle.js index 5a12a61d494..6794e8d4199 100644 --- a/lib/internal/cluster/round_robin_handle.js +++ b/lib/internal/cluster/round_robin_handle.js @@ -2,7 +2,6 @@ const assert = require('internal/assert'); const net = require('net'); const { sendHelper } = require('internal/cluster/utils'); -const uv = internalBinding('uv'); const { constants } = internalBinding('tcp_wrap'); module.exports = RoundRobinHandle; @@ -58,10 +57,7 @@ RoundRobinHandle.prototype.add = function(worker, send) { // Still busy binding. this.server.once('listening', done); this.server.once('error', (err) => { - // Hack: translate 'EADDRINUSE' error string back to numeric error code. - // It works but ideally we'd have some backchannel between the net and - // cluster modules for stuff like this. - send(uv[`UV_${err.errno}`], null); + send(err.errno, null); }); }; |