diff --git a/lib/dns.js b/lib/dns.js index af5416c62478cc1..f60c9771b04bc4b 100644 --- a/lib/dns.js +++ b/lib/dns.js @@ -44,6 +44,7 @@ const { emitInvalidHostnameWarning, getDefaultVerbatim, setDefaultResultOrder, + errorCodes, } = require('internal/dns/utils'); const { ERR_INVALID_ARG_TYPE, @@ -351,30 +352,7 @@ 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' + ...errorCodes, }; bindDefaultResolver(module.exports, getDefaultResolver()); diff --git a/lib/internal/dns/promises.js b/lib/internal/dns/promises.js index 9625e9e7b9b6eac..ce7ada41529c357 100644 --- a/lib/internal/dns/promises.js +++ b/lib/internal/dns/promises.js @@ -16,6 +16,7 @@ const { validateTries, emitInvalidHostnameWarning, getDefaultVerbatim, + errorCodes, } = require('internal/dns/utils'); const { codes, dnsException } = require('internal/errors'); const { toASCII } = require('internal/idna'); @@ -313,5 +314,5 @@ Resolver.prototype.resolve = function resolve(hostname, rrtype) { }; -module.exports = { lookup, lookupService, Resolver }; +module.exports = { lookup, lookupService, Resolver, ...errorCodes }; bindDefaultResolver(module.exports, Resolver.prototype); diff --git a/lib/internal/dns/utils.js b/lib/internal/dns/utils.js index 62606e6f7f0aaf0..3c61bdb706775a9 100644 --- a/lib/internal/dns/utils.js +++ b/lib/internal/dns/utils.js @@ -201,6 +201,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, @@ -212,4 +240,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 5fd20dff2c12d23..d88ecefaa985cae 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);