denoland/deno · error · TypeError

ERR_MISSING_ARGS

ERR_MISSING_ARGS

Error message

The "address", "port", and "callback" arguments must be specified

What it means

dns.lookupService(address, port, callback) performs a strict arity check: it must be called with exactly 3 arguments. Fewer arguments (missing callback, port, or address) — and also extra arguments — throw ERR_MISSING_ARGS before any validation of the values themselves.

Source

Thrown at ext/node/polyfills/dns.ts:354

) {
  if (err) {
    return this.callback!(handleDnsError(err, "getnameinfo", this.address));
  }

  this.callback!(err, hostname, service);
}

function lookupService(
  address: string,
  port: number,
  callback: (
    err: ErrnoException | null,
    hostname?: string,
    service?: string,
  ) => void,
): GetNameInfoReqWrap {
  if (arguments.length !== 3) {
    throw new ERR_MISSING_ARGS("address", "port", "callback");
  }

  if (isIP(address) === 0) {
    throw new ERR_INVALID_ARG_VALUE("address", address);
  }

  port = validatePort(port);

  validateFunction(callback, "callback");

  const req = new GetNameInfoReqWrap();
  req.callback = callback;
  req.address = address;
  req.port = port;
  req.oncomplete = onlookupservice;

  const errCode = cares.getnameinfo(req, address, port);
  if (errCode) {

View on GitHub (pinned to 89f33cbef2)

Solutions

  1. Always supply all three: dns.lookupService(address, port, (err, hostname, service) => {})
  2. In wrappers, check arguments.length === 3 (or fn.length usage) before delegating
  3. Use the promise form (dnsPromises.lookupService) if you do not need a callback, keeping the two-value signature

Example fix

// before
dns.lookupService('127.0.0.1', 80); // missing callback -> ERR_MISSING_ARGS

// after
dns.lookupService('127.0.0.1', 80, (err, hostname, service) => {
  if (err) throw err;
  console.log(hostname, service);
});
Defensive patterns

Strategy: validation

Validate before calling

function lookupServiceSafe(address, port, callback) {
  if (arguments.length !== 3) throw new Error('lookupService requires (address, port, callback)');
  return dns.lookupService(address, port, callback);
}

Try / catch

catch (e) { if (e?.code === 'ERR_MISSING_ARGS') return reply(400, 'address, port and callback are required'); throw e; }

Prevention

When it happens

Trigger: dns.lookupService('127.0.0.1') or dns.lookupService('127.0.0.1', 80) without a callback; spreading an args array of the wrong length; calling with a 4th stray argument.

Common situations: Copy-pasting lookup()-style two-arg calls onto lookupService; optional-callback wrappers that pass undefined and still hit the !== 3 length check via extra arguments; adapting promise wrappers that forget the callback.

Related errors


AI-assisted analysis of denoland/deno@89f33cbef2 (2026-08-16). Data as JSON: /api/errors/8a00ac6a25a6852f. Report an issue: GitHub.