mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
1432065e9d
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>
29 lines
904 B
JavaScript
29 lines
904 B
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
const dnstools = require('../common/dns');
|
|
const { Resolver } = require('dns');
|
|
const assert = require('assert');
|
|
const dgram = require('dgram');
|
|
|
|
const server = dgram.createSocket('udp4');
|
|
const resolver = new Resolver();
|
|
|
|
server.bind(0, common.mustCall(() => {
|
|
resolver.setServers([`127.0.0.1:${server.address().port}`]);
|
|
resolver.reverse('123.45.67.89', common.mustCall((err, res) => {
|
|
assert.strictEqual(err.code, 'ECANCELLED');
|
|
assert.strictEqual(err.syscall, 'getHostByAddr');
|
|
assert.strictEqual(err.hostname, '123.45.67.89');
|
|
server.close();
|
|
}));
|
|
}));
|
|
|
|
server.on('message', common.mustCall((msg, { address, port }) => {
|
|
const parsed = dnstools.parseDNSPacket(msg);
|
|
const domain = parsed.questions[0].domain;
|
|
assert.strictEqual(domain, '89.67.45.123.in-addr.arpa');
|
|
|
|
// Do not send a reply.
|
|
resolver.cancel();
|
|
}));
|