Skip to content

Error message could be improved for dns.lookupService #29039

Description

@ORESoftware

I am on Node.js v12.6

I have this issue:
nodejs/help#2106

I think the error message is mis-named. The error message should be:

There was an error: TypeError [ERR_INVALID_OPT_VALUE]: The value "google.com" is invalid for option "address"

but the error message is:

There was an error: TypeError [ERR_INVALID_OPT_VALUE]: The value "google.com" is invalid for option "hostname"

this will work:

const dns = require('dns');

const getDNSInfo = (host) => new Promise(resolve => {
  dns.lookup(host, (err, hostname, service) => {
    console.log('dns resolved:', {hostname, service, err});
    resolve({err, hostname, service});
  });
});

getDNSInfo('google.com').then(v => {
   console.log(v);
})
.catch(v => {
  console.error('There was an error:', v)
});

but this doesn't:

const dns = require('dns');

const getDNSInfo = (host, port) => new Promise(resolve => {
  dns.lookupService(host, port, (err, hostname, service) => {
    console.log('dns resolved:', {hostname, service, err});
    resolve({err, hostname, service});
  });
});

getDNSInfo('google.com', 80).then(v => {
   console.log(v);
})
.catch(v => {
  console.error('There was an error:', v)
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions