{"record":{"id":"4089d4ba7469e867","repo":"denoland/deno","slug":"err-invalid-arg-value-4089d4","errorCode":"ERR_INVALID_ARG_VALUE","errorMessage":"The argument 'address' is invalid. Received ${address}","messagePattern":"The argument 'address' is invalid\\. Received (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"ext/node/polyfills/dns.ts","lineNumber":358,"sourceCode":"\n  this.callback!(err, hostname, service);\n}\n\nfunction lookupService(\n  address: string,\n  port: number,\n  callback: (\n    err: ErrnoException | null,\n    hostname?: string,\n    service?: string,\n  ) => void,\n): GetNameInfoReqWrap {\n  if (arguments.length !== 3) {\n    throw new ERR_MISSING_ARGS(\"address\", \"port\", \"callback\");\n  }\n\n  if (isIP(address) === 0) {\n    throw new ERR_INVALID_ARG_VALUE(\"address\", address);\n  }\n\n  port = validatePort(port);\n\n  validateFunction(callback, \"callback\");\n\n  const req = new GetNameInfoReqWrap();\n  req.callback = callback;\n  req.address = address;\n  req.port = port;\n  req.oncomplete = onlookupservice;\n\n  const errCode = cares.getnameinfo(req, address, port);\n  if (errCode) {\n    throw dnsException(errCode, \"getnameinfo\", address);\n  }\n\n  return req;","sourceCodeStart":340,"sourceCodeEnd":376,"githubUrl":"https://github.com/denoland/deno/blob/89f33cbef296a2b287f323d42de54c871fa69c77/ext/node/polyfills/dns.ts#L340-L376","documentation":"Before doing reverse resolution, dns.lookupService verifies the address with isIP() and throws ERR_INVALID_ARG_VALUE when isIP(address) === 0 — i.e. the argument is not a literal IPv4/IPv6 address. Hostnames are not accepted here; lookupService expects an already-resolved IP.","triggerScenarios":"dns.lookupService('localhost', 80, cb); dns.lookupService('example.com', 443, cb); malformed literals like '192.168.1' or 'fe80::1%eth0 ' (whitespace).","commonSituations":"Feeding request remote addresses that are actually hostnames in test setups; using req.socket.remoteAddress output after it became undefined and stringified to 'undefined'; proxies passing Host header values.","solutions":["Resolve first: dns.lookup(hostname, (e, { address }) => dns.lookupService(address, port, cb))","Guard with net.isIP(address) !== 0 before calling","Trim/normalize the string — surrounding whitespace makes a valid literal invalid"],"exampleFix":"// before\ndns.lookupService('localhost', 80, cb); // not an IP literal -> throws\n\n// after\ndns.lookup('localhost', (err, { address }) => {\n  if (err) throw err;\n  dns.lookupService(address, 80, cb);\n});","handlingStrategy":"validation","validationCode":"const { isIP } = require('node:net');\nif (isIP(String(address).trim()) === 0) {\n  // resolve hostnames first, or reject\n  return dns.lookup(address, (e, { address: ip }) => dns.lookupService(ip, port, cb));\n}\ndns.lookupService(address, port, cb);","typeGuard":"const isIpLiteral = (s) => net.isIP(String(s ?? '')) !== 0;","tryCatchPattern":"catch (e) { if (e?.code === 'ERR_INVALID_ARG_VALUE') return cb(null); /* skip non-IP peers */ throw e; }","preventionTips":["Filter request logs through net.isIP before reverse lookup","Normalize remoteAddress values (strip scope ids, trim whitespace)","Treat missing remote addresses as skip, not as 'undefined' strings"],"tags":["node-compat","dns","validation","network"],"backgroundTag":null,"analyzedSha":"89f33cbef296a2b287f323d42de54c871fa69c77","analyzedAt":"2026-08-16T07:54:21.310Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}