{"id":"0acf834c5b2d61c3","repo":"sindresorhus/got","slug":"invalid-dns-lookup-ip-version-value-as-string","errorCode":null,"errorMessage":"Invalid DNS lookup IP version: ${value as string}","messagePattern":"Invalid DNS lookup IP version: (.+?)","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"source/core/options.ts","lineNumber":2948,"sourceCode":"\t}\n\n\t/**\n\tIndicates which DNS record family to use.\n\n\tValues:\n\t- `undefined`: IPv4 (if present) or IPv6\n\t- `4`: Only IPv4\n\t- `6`: Only IPv6\n\n\t@default undefined\n\t*/\n\tget dnsLookupIpVersion(): DnsLookupIpVersion {\n\t\treturn this.#internals.dnsLookupIpVersion;\n\t}\n\n\tset dnsLookupIpVersion(value: DnsLookupIpVersion) {\n\t\tif (value !== undefined && value !== 4 && value !== 6) {\n\t\t\tthrow new TypeError(`Invalid DNS lookup IP version: ${value as string}`);\n\t\t}\n\n\t\tthis.#internals.dnsLookupIpVersion = value;\n\t}\n\n\t/**\n\tA function used to parse JSON responses.\n\n\t@example\n\t```\n\timport got from 'got';\n\timport Bourne from '@hapi/bourne';\n\n\tconst parsed = await got('https://example.com', {\n\t\tparseJson: text => Bourne.parse(text)\n\t}).json();\n\n\tconsole.log(parsed);","sourceCodeStart":2930,"sourceCodeEnd":2966,"githubUrl":"https://github.com/sindresorhus/got/blob/e3924aa1e53a6ca3eb93a43618ce532442a89b40/source/core/options.ts#L2930-L2966","documentation":"Thrown by the `dnsLookupIpVersion` setter when the value is anything other than `undefined`, `4`, or `6`. The option pins DNS resolution to an IP family and only those three values are meaningful, so any other input (a string like `'ipv4'`, a boolean, or a wrong number) is rejected.","triggerScenarios":"Calling `got(url, {dnsLookupIpVersion: 'ipv4'})`, `{dnsLookupIpVersion: 4.0}`, `{dnsLookupIpVersion: true}`, or any value that is not exactly `undefined`, `4`, or `6`.","commonSituations":"Passing a string label (`'ipv4'`/`'ipv6'`) instead of the numeric family; passing a stringified number from env vars or config files.","solutions":["Pass one of `undefined`, `4`, or `6` (numbers, not strings).","If the value comes from config/env, coerce explicitly: `Number(value)` and validate before passing.","Map labels to numbers: `{ipv4: 4, ipv6: 6}[label]`."],"exampleFix":"// before\nawait got(url, {dnsLookupIpVersion: 'ipv4'});\n// after\nawait got(url, {dnsLookupIpVersion: 4});","handlingStrategy":"type-guard","validationCode":"function normalizeDnsVersion(value) {\n  const map = {ipv4: 4, ipv6: 6, 4: 4, 6: 6, undefined};\n  const v = map[value] ?? value;\n  if (v !== undefined && v !== 4 && v !== 6) {\n    throw new TypeError(`dnsLookupIpVersion must be undefined, 4, or 6; got ${value}`);\n  }\n  return v;\n}","typeGuard":"function isDnsLookupIpVersion(v: unknown): v is undefined | 4 | 6 {\n  return v === undefined || v === 4 || v === 6;\n}","tryCatchPattern":null,"preventionTips":["Pass numbers (`4`/`6`), never string labels.","Coerce env/config values with `Number()` and validate before passing."],"tags":["options","dns","validation","config","network"],"analyzedSha":"e3924aa1e53a6ca3eb93a43618ce532442a89b40","analyzedAt":"2026-08-03T19:22:24.770Z","schemaVersion":2}