summaryrefslogtreecommitdiff
path: root/test/parallel/test-dgram-send-error.js
diff options
context:
space:
mode:
authorJoyee Cheung <joyeec9h3@gmail.com>2019-06-09 21:04:51 +0800
committerJoyee Cheung <joyeec9h3@gmail.com>2019-06-17 10:18:09 +0800
commit1432065e9dc77218507f328b63cb7f5d279dd6e9 (patch)
tree0f4273124106700d9069281b6588b64a4ccf2b2d /test/parallel/test-dgram-send-error.js
parent28d3f1963a98ce157b360c0a3ba70fb8e1f73f60 (diff)
downloadandroid-node-v8-1432065e9dc77218507f328b63cb7f5d279dd6e9.tar.gz
android-node-v8-1432065e9dc77218507f328b63cb7f5d279dd6e9.tar.bz2
android-node-v8-1432065e9dc77218507f328b63cb7f5d279dd6e9.zip
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 'test/parallel/test-dgram-send-error.js')
-rw-r--r--test/parallel/test-dgram-send-error.js3
1 files changed, 2 insertions, 1 deletions
diff --git a/test/parallel/test-dgram-send-error.js b/test/parallel/test-dgram-send-error.js
index f6d37f2c81..6aa326c8ec 100644
--- a/test/parallel/test-dgram-send-error.js
+++ b/test/parallel/test-dgram-send-error.js
@@ -5,6 +5,7 @@ const assert = require('assert');
const dgram = require('dgram');
const { internalBinding } = require('internal/test/binding');
const { UV_UNKNOWN } = internalBinding('uv');
+const { getSystemErrorName } = require('util');
const { kStateSymbol } = require('internal/dgram');
const mockError = new Error('mock DNS error');
@@ -50,7 +51,7 @@ getSocket((socket) => {
const callback = common.mustCall((err) => {
socket.close();
assert.strictEqual(err.code, 'UNKNOWN');
- assert.strictEqual(err.errno, 'UNKNOWN');
+ assert.strictEqual(getSystemErrorName(err.errno), 'UNKNOWN');
assert.strictEqual(err.syscall, 'send');
assert.strictEqual(err.address, common.localhostIPv4);
assert.strictEqual(err.port, port);