Skip to content

dns.lookup allows a "falsy" hostname, but behaviour is undocumented and appears useless #13119

Closed
@sam-github

Description

@sam-github

I assumed this was a bug, but on looking into it, it seems deliberate:

node/lib/dns.js

Line 132 in 6f21671

'hostname must be a string or falsey');

@cjihrig you added this, I think, in 5086d6e (missing PR metadata), but it looks like you were cleaning up something from an earlier commit. Any ideas why falsey is allowed?

Its even tested:

assert.doesNotThrow(() => {
dns.lookup(false, {
hints: 0,
family: 0,
all: true
}, common.mustCall((error, result, addressType) => {
assert.ifError(error);
assert.deepStrictEqual(result, []);
assert.strictEqual(addressType, undefined);
}));
});
, but I'm not sure if the test assertions were just to add coverage, or were because that was the expected output, @abouthiroppy added them in #10844, do you have any comments?

My guess was that the intention is that if hostname is falsy, there may be enough information in options to return a useful value, in which case options should be mandatory if hostname is missing.

Except... I don't see how that can be, it looks to me you will always get no results no matter what flags you put into options, and the tests even assert that, so... why is a falsey hostname allowed?

  • Version: *
  • Platform: *
  • Subsystem: dns
% ./node
> dns.lookup(false, console.log)
{}
> null null 4

Metadata

Metadata

Assignees

No one assigned

    Labels

    dnsIssues and PRs related to the dns subsystem.help wantedIssues that need assistance from volunteers or PRs that need help to proceed.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions