SIGN IN SIGN UP
denoland / deno UNCLAIMED

A modern runtime for JavaScript and TypeScript.

0 0 16 Rust

fix(ext/node): report real error code for failed dns.lookup (#34697)

The original issue — `node:dns.lookup` (and npm packages built on it,
e.g. `mongodb`, `mysql`, `ioredis`) ignoring `/etc/hosts` — was fixed by
#27936, which switched `dns.lookup` to resolve through `getaddrinfo`.
`getaddrinfo` consults the operating-system resolver, which reads the
hosts file on every platform, so hostnames defined in `/etc/hosts` (or
`--add-host` / docker-compose `extra_hosts`) now resolve correctly.

This PR closes out the remaining gap from the original report: the
**error output** of a failed lookup did not match Node.js.

When a lookup failed, `cares.getaddrinfo` caught the error and flattened
*every* failure to `EAI_NODATA` (errno `-3007`). So an unresolvable host
reported:

```
{ errno: -3007, code: "ENOTFOUND", syscall: "getaddrinfo", hostname: "…" }
```

while Node.js reports `errno: -3008` (`UV_EAI_NONAME`). The exact
`-3007` mismatch is visible in the original issue report.

The Rust op (`op_node_getaddrinfo`) already maps the libc/WinSock result
to the correct libuv error code and exposes it on the thrown error via
the `uv_errcode` property. This change simply propagates that code
instead of discarding it, so failed lookups now report the same
`errno`/`code` as Node.js. Permission failures (`EPERM`) and the
no-results case keep their existing behavior.

### Tests

Adds regression tests in `tests/unit_node/dns_test.ts`:
- `dns.lookup` / `dns.promises.lookup` resolve `localhost` via the
system resolver / hosts file.
- An unresolvable host reports `code: "ENOTFOUND"`, `errno: -3008`,
`syscall: "getaddrinfo"`, matching Node.js.

Closes #25927

Closes denoland/divybot#410

Co-authored-by: divybot <divybot@users.noreply.github.com>
Co-authored-by: Divy Srivastava <me@littledivy.com>
E
em committed
e086b32ad226222e6c112cbf6afe05f0bc5a7fd3
Parent: 20b2881
Committed by GitHub <noreply@github.com> on 6/2/2026, 6:50:41 AM