diff --git a/doc/api/dns.md b/doc/api/dns.md index addc4fe9d18de6..72d57e4f7e2f41 100644 --- a/doc/api/dns.md +++ b/doc/api/dns.md @@ -1293,6 +1293,8 @@ Each DNS query can return one of the following error codes: * `dns.ADDRGETNETWORKPARAMS`: Could not find `GetNetworkParams` function. * `dns.CANCELLED`: DNS query cancelled. +The above error codes are also exported by the `dnsPromises` API, e.g., `dnsPromises.NODATA`. + ## Implementation considerations Although [`dns.lookup()`][] and the various `dns.resolve*()/dns.reverse()` diff --git a/lib/dns.js b/lib/dns.js index d768a863326376..7d3b2d46b6e5db 100644 --- a/lib/dns.js +++ b/lib/dns.js @@ -44,7 +44,34 @@ const { emitInvalidHostnameWarning, getDefaultVerbatim, setDefaultResultOrder, + errorCodes: dnsErrorCodes, } = require('internal/dns/utils'); +const { + NODATA, + FORMERR, + SERVFAIL, + NOTFOUND, + NOTIMP, + REFUSED, + BADQUERY, + BADNAME, + BADFAMILY, + BADRESP, + CONNREFUSED, + TIMEOUT, + EOF, + FILE, + NOMEM, + DESTRUCTION, + BADSTR, + BADFLAGS, + NONAME, + BADHINTS, + NOTINITIALIZED, + LOADIPHLPAPI, + ADDRGETNETWORKPARAMS, + CANCELLED, +} = dnsErrorCodes; const { ERR_INVALID_ARG_TYPE, ERR_INVALID_ARG_VALUE, @@ -352,30 +379,30 @@ module.exports = { V4MAPPED: cares.AI_V4MAPPED, // ERROR CODES - NODATA: 'ENODATA', - FORMERR: 'EFORMERR', - SERVFAIL: 'ESERVFAIL', - NOTFOUND: 'ENOTFOUND', - NOTIMP: 'ENOTIMP', - REFUSED: 'EREFUSED', - BADQUERY: 'EBADQUERY', - BADNAME: 'EBADNAME', - BADFAMILY: 'EBADFAMILY', - BADRESP: 'EBADRESP', - CONNREFUSED: 'ECONNREFUSED', - TIMEOUT: 'ETIMEOUT', - EOF: 'EOF', - FILE: 'EFILE', - NOMEM: 'ENOMEM', - DESTRUCTION: 'EDESTRUCTION', - BADSTR: 'EBADSTR', - BADFLAGS: 'EBADFLAGS', - NONAME: 'ENONAME', - BADHINTS: 'EBADHINTS', - NOTINITIALIZED: 'ENOTINITIALIZED', - LOADIPHLPAPI: 'ELOADIPHLPAPI', - ADDRGETNETWORKPARAMS: 'EADDRGETNETWORKPARAMS', - CANCELLED: 'ECANCELLED' + NODATA, + FORMERR, + SERVFAIL, + NOTFOUND, + NOTIMP, + REFUSED, + BADQUERY, + BADNAME, + BADFAMILY, + BADRESP, + CONNREFUSED, + TIMEOUT, + EOF, + FILE, + NOMEM, + DESTRUCTION, + BADSTR, + BADFLAGS, + NONAME, + BADHINTS, + NOTINITIALIZED, + LOADIPHLPAPI, + ADDRGETNETWORKPARAMS, + CANCELLED, }; bindDefaultResolver(module.exports, getDefaultResolver()); diff --git a/lib/internal/dns/promises.js b/lib/internal/dns/promises.js index 90ae3fcdc2b016..633ed44fed747e 100644 --- a/lib/internal/dns/promises.js +++ b/lib/internal/dns/promises.js @@ -16,7 +16,34 @@ const { validateTries, emitInvalidHostnameWarning, getDefaultVerbatim, + errorCodes: dnsErrorCodes, } = require('internal/dns/utils'); +const { + NODATA, + FORMERR, + SERVFAIL, + NOTFOUND, + NOTIMP, + REFUSED, + BADQUERY, + BADNAME, + BADFAMILY, + BADRESP, + CONNREFUSED, + TIMEOUT, + EOF, + FILE, + NOMEM, + DESTRUCTION, + BADSTR, + BADFLAGS, + NONAME, + BADHINTS, + NOTINITIALIZED, + LOADIPHLPAPI, + ADDRGETNETWORKPARAMS, + CANCELLED, +} = dnsErrorCodes; const { codes, dnsException } = require('internal/errors'); const { toASCII } = require('internal/idna'); const { isIP } = require('internal/net'); @@ -309,5 +336,35 @@ Resolver.prototype.resolve = function resolve(hostname, rrtype) { }; -module.exports = { lookup, lookupService, Resolver }; +module.exports = { + lookup, + lookupService, + Resolver, + + // ERROR CODES + NODATA, + FORMERR, + SERVFAIL, + NOTFOUND, + NOTIMP, + REFUSED, + BADQUERY, + BADNAME, + BADFAMILY, + BADRESP, + CONNREFUSED, + TIMEOUT, + EOF, + FILE, + NOMEM, + DESTRUCTION, + BADSTR, + BADFLAGS, + NONAME, + BADHINTS, + NOTINITIALIZED, + LOADIPHLPAPI, + ADDRGETNETWORKPARAMS, + CANCELLED, +}; bindDefaultResolver(module.exports, Resolver.prototype); diff --git a/lib/internal/dns/utils.js b/lib/internal/dns/utils.js index fa7e19c784789c..26949a028d89c7 100644 --- a/lib/internal/dns/utils.js +++ b/lib/internal/dns/utils.js @@ -207,6 +207,34 @@ function setDefaultResultOrder(value) { dnsOrder = value; } +// ERROR CODES +const errorCodes = { + NODATA: 'ENODATA', + FORMERR: 'EFORMERR', + SERVFAIL: 'ESERVFAIL', + NOTFOUND: 'ENOTFOUND', + NOTIMP: 'ENOTIMP', + REFUSED: 'EREFUSED', + BADQUERY: 'EBADQUERY', + BADNAME: 'EBADNAME', + BADFAMILY: 'EBADFAMILY', + BADRESP: 'EBADRESP', + CONNREFUSED: 'ECONNREFUSED', + TIMEOUT: 'ETIMEOUT', + EOF: 'EOF', + FILE: 'EFILE', + NOMEM: 'ENOMEM', + DESTRUCTION: 'EDESTRUCTION', + BADSTR: 'EBADSTR', + BADFLAGS: 'EBADFLAGS', + NONAME: 'ENONAME', + BADHINTS: 'EBADHINTS', + NOTINITIALIZED: 'ENOTINITIALIZED', + LOADIPHLPAPI: 'ELOADIPHLPAPI', + ADDRGETNETWORKPARAMS: 'EADDRGETNETWORKPARAMS', + CANCELLED: 'ECANCELLED', +}; + module.exports = { bindDefaultResolver, getDefaultResolver, @@ -218,4 +246,5 @@ module.exports = { emitInvalidHostnameWarning, getDefaultVerbatim, setDefaultResultOrder, + errorCodes, }; diff --git a/test/parallel/test-dns-promises-exists.js b/test/parallel/test-dns-promises-exists.js index 5fd20dff2c12d2..d88ecefaa985ca 100644 --- a/test/parallel/test-dns-promises-exists.js +++ b/test/parallel/test-dns-promises-exists.js @@ -2,5 +2,32 @@ require('../common'); const assert = require('assert'); +const dnsPromises = require('dns/promises'); +const dns = require('dns'); -assert.strictEqual(require('dns/promises'), require('dns').promises); +assert.strictEqual(dnsPromises, dns.promises); + +assert.strictEqual(dnsPromises.NODATA, dns.NODATA); +assert.strictEqual(dnsPromises.FORMERR, dns.FORMERR); +assert.strictEqual(dnsPromises.SERVFAIL, dns.SERVFAIL); +assert.strictEqual(dnsPromises.NOTFOUND, dns.NOTFOUND); +assert.strictEqual(dnsPromises.NOTIMP, dns.NOTIMP); +assert.strictEqual(dnsPromises.REFUSED, dns.REFUSED); +assert.strictEqual(dnsPromises.BADQUERY, dns.BADQUERY); +assert.strictEqual(dnsPromises.BADNAME, dns.BADNAME); +assert.strictEqual(dnsPromises.BADFAMILY, dns.BADFAMILY); +assert.strictEqual(dnsPromises.BADRESP, dns.BADRESP); +assert.strictEqual(dnsPromises.CONNREFUSED, dns.CONNREFUSED); +assert.strictEqual(dnsPromises.TIMEOUT, dns.TIMEOUT); +assert.strictEqual(dnsPromises.EOF, dns.EOF); +assert.strictEqual(dnsPromises.FILE, dns.FILE); +assert.strictEqual(dnsPromises.NOMEM, dns.NOMEM); +assert.strictEqual(dnsPromises.DESTRUCTION, dns.DESTRUCTION); +assert.strictEqual(dnsPromises.BADSTR, dns.BADSTR); +assert.strictEqual(dnsPromises.BADFLAGS, dns.BADFLAGS); +assert.strictEqual(dnsPromises.NONAME, dns.NONAME); +assert.strictEqual(dnsPromises.BADHINTS, dns.BADHINTS); +assert.strictEqual(dnsPromises.NOTINITIALIZED, dns.NOTINITIALIZED); +assert.strictEqual(dnsPromises.LOADIPHLPAPI, dns.LOADIPHLPAPI); +assert.strictEqual(dnsPromises.ADDRGETNETWORKPARAMS, dns.ADDRGETNETWORKPARAMS); +assert.strictEqual(dnsPromises.CANCELLED, dns.CANCELLED);