Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error message could be improved for dns.lookupService #29039

Closed
ORESoftware opened this issue Aug 7, 2019 · 1 comment
Closed

Error message could be improved for dns.lookupService #29039

ORESoftware opened this issue Aug 7, 2019 · 1 comment

Comments

@ORESoftware
Copy link
Contributor

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)
});
@Trott
Copy link
Member

Trott commented Aug 8, 2019

@nodejs/dns

@Trott Trott closed this as completed in df936c5 Aug 11, 2019
targos pushed a commit that referenced this issue Aug 19, 2019
The first argument to lookupService() should be an IP address,
and is named "address" in the documentation. This commit updates
the code to match the documentation and provide less confusing
errors.

PR-URL: #29040
Fixes: #29039
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants