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

Re-export error code constants from dns/promises #43140

Closed
leftshift opened this issue May 18, 2022 · 1 comment · Fixed by #43176
Closed

Re-export error code constants from dns/promises #43140

leftshift opened this issue May 18, 2022 · 1 comment · Fixed by #43176
Labels
feature request Issues that request new features to be added to Node.js.

Comments

@leftshift
Copy link

leftshift commented May 18, 2022

What is the problem this feature will solve?

When writing code that uses the promise based dns library, it's quite convenient to just import dns/promises.

However, when checking for the type of error with err.code, it's nicer and more robust to do a comparisons with the error code constants instead of doing a string comparison:

try {
  res = await dns.resolve4([...])
} catch(e) {
  if (e.code == dns.NOTFOUND) { // instead of e.code == 'ENOTFOUND'
    [...]
  }
}

However, unfortunately, NOTFOUND and friends are only exported from the dns module, not from dns/promises.

What is the feature you are proposing to solve the problem?

Re-Export all dns error code constants from dns/promises.

What alternatives have you considered?

Alternatively, code needs to either import dns and dns/promises under different names (which might be a bit confusing), or just import dns and use the promise based api through dns.promises (seems needlessly verbose).

@leftshift leftshift added the feature request Issues that request new features to be added to Node.js. label May 18, 2022
@aduh95
Copy link
Contributor

aduh95 commented May 18, 2022

The same applies to node:fs, currently my goto way is to

import { promises as fs, constants as fsConstants } from 'node:fs'
import { promises as dns, constants as dnsConstants } from 'node:dns'

Would you like to send a PR to address that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Issues that request new features to be added to Node.js.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants