{"record":{"id":"b20d69de58ea1cde","repo":"denoland/deno","slug":"err-invalid-arg-type-b20d69","errorCode":"ERR_INVALID_ARG_TYPE","errorMessage":"The \"options\" argument must be of type object or integer. Received ${actual}","messagePattern":"The \"options\" argument must be of type object or integer\\. Received (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"ext/node/polyfills/dns.ts","lineNumber":219,"sourceCode":"  let port = undefined;\n\n  // Parse arguments\n  if (hostname) {\n    validateString(hostname, \"hostname\");\n  }\n\n  if (isLookupCallback(options)) {\n    callback = options;\n    family = 0;\n  } else if (isFamily(options)) {\n    validateFunction(callback, \"callback\");\n\n    validateOneOf(options, \"family\", validFamilies);\n    family = options;\n  } else if (!isLookupOptions(options)) {\n    validateFunction(arguments.length === 2 ? options : callback, \"callback\");\n\n    throw new ERR_INVALID_ARG_TYPE(\"options\", [\"integer\", \"object\"], options);\n  } else {\n    validateFunction(callback, \"callback\");\n\n    if (options?.hints != null) {\n      validateNumber(options.hints, \"options.hints\");\n      hints = options.hints >>> 0;\n      validateHints(hints);\n    }\n\n    if (options?.family != null) {\n      // Accept both numeric (0, 4, 6) and string ('IPv4', 'IPv6') family values\n      // to match Node.js behavior\n      switch (options.family) {\n        case \"IPv4\":\n          family = 4;\n          break;\n        case \"IPv6\":\n          family = 6;","sourceCodeStart":201,"sourceCodeEnd":237,"githubUrl":"https://github.com/denoland/deno/blob/89f33cbef296a2b287f323d42de54c871fa69c77/ext/node/polyfills/dns.ts#L201-L237","documentation":"dns.lookup's second parameter is polymorphic: a function (treated as the callback), a number (an IP family, later validated against 0/4/6), or an object/undefined (lookup options). Any other type — string, boolean, bigint, symbol — reaches the final else-branch and throws ERR_INVALID_ARG_TYPE for 'options'.","triggerScenarios":"dns.lookup('example.com', 'IPv4', cb) (family string instead of an options object); dns.lookup(host, true, cb); dns.lookup(host, 4n, cb); passing an array of families.","commonSituations":"Porting getaddrinfo-style code where family was a string; config values typed as '4'/'6' strings; passing { family: 4 } correctly but passing '4' bare as the shorthand.","solutions":["Use the numeric shorthand dns.lookup(host, 4, cb) or the options object dns.lookup(host, { family: 4 }, cb)","Coerce config-provided families: Number(family) guarded by Number.isInteger","For 'IPv4'/'IPv6' strings, pass them inside the options object ({ family: 'IPv6' }), which the polyfill accepts"],"exampleFix":"// before\ndns.lookup('example.com', 'IPv6', (err, addr) => {}); // string options -> throws\n\n// after\ndns.lookup('example.com', { family: 'IPv6' }, (err, addr) => {});","handlingStrategy":"validation","validationCode":"// Normalize the polymorphic second arg before dns.lookup\nfunction normalizeLookupArgs(hostname, options, callback) {\n  if (typeof options === 'function') return [hostname, 0, options];\n  if (typeof options === 'number') return [hostname, options, callback];\n  if (options == null || typeof options === 'object') return [hostname, options ?? {}, callback];\n  throw new TypeError(`bad lookup options: ${typeof options}`);\n}","typeGuard":"const isLookupOptionsLike = (v) =>\n  typeof v === 'function' || typeof v === 'number' || typeof v === 'object' || typeof v === 'undefined';","tryCatchPattern":null,"preventionTips":["Pass family as a number or inside an options object — never a bare string","Coerce config-driven families with Number() plus Number.isInteger check","Wrap dns.lookup once in a typed helper so all call sites share the normalization"],"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"}