{"record":{"id":"4ef9362f5abc5d91","repo":"denoland/deno","slug":"invalid-url-raw","errorCode":null,"errorMessage":"Invalid URL: ${raw}","messagePattern":"Invalid URL: (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"ext/node/polyfills/_http_proxy.js","lineNumber":108,"sourceCode":"}\n\nfunction readEnvKey(env, keys) {\n  for (let i = 0; i < keys.length; i++) {\n    const k = keys[i];\n    if (env[k] !== undefined && env[k] !== \"\") {\n      return env[k];\n    }\n  }\n  return undefined;\n}\n\nconst CRLF_RE = new SafeRegExp(/[\\r\\n]/);\n\nfunction parseProxyUrl(raw, kind, mode) {\n  if (raw === undefined || raw === null || raw === \"\") return null;\n  if (typeof raw !== \"string\") {\n    if (mode === \"env\") {\n      throw new TypeError(`Invalid URL: ${raw}`);\n    }\n    throw new ERR_PROXY_INVALID_CONFIG(\n      `Invalid proxy URL for ${kind}: must be a string`,\n    );\n  }\n  // CRLF injection guard - check raw string before URL parsing strips them.\n  // Matches Node's CRLF rejection in the proxy URL validator. We surface this\n  // even for env-derived URLs so the auth tests get the expected error class.\n  if (RegExpPrototypeExec(CRLF_RE, raw) !== null) {\n    throw new ERR_PROXY_INVALID_CONFIG(`Invalid proxy URL: ${raw}`);\n  }\n  let url;\n  try {\n    url = new URL(raw);\n  } catch {\n    if (mode === \"env\") {\n      throw new TypeError(`Invalid URL: ${raw}`);\n    }","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/denoland/deno/blob/89f33cbef296a2b287f323d42de54c871fa69c77/ext/node/polyfills/_http_proxy.js#L90-L126","documentation":"In env mode (proxy config derived from the process environment via NODE_USE_ENV_PROXY=1 or --use-env-proxy), parseProxyUrl throws a plain TypeError 'Invalid URL: <raw>' when the value found for http_proxy/https_proxy is not a string. This mirrors Node v24, which reports bad env-derived proxy values as a TypeError rather than a coded Node error.","triggerScenarios":"NODE_USE_ENV_PROXY active and a proxy variable resolves to a non-string - e.g. a programmatically composed env object (tests, custom harnesses calling buildProxyConfig in env mode) with http_proxy: 123. With the real process environment values are always strings, so this branch mostly fires through programmatic env injection. The error surfaces lazily on the first http/https request that initializes proxy state.","commonSituations":"Tests injecting fake env dictionaries with untyped values; wrappers that build env-like objects from JSON config where a number slips in.","solutions":["Ensure HTTP_PROXY/HTTPS_PROXY values are URL strings before enabling NODE_USE_ENV_PROXY","Cast/coerce proxy env values to strings when composing env objects programmatically","Wrap the first request in try/catch for TypeError and fall back to a direct connection if the proxy env is broken"],"exampleFix":"// before\nconst fakeEnv = { http_proxy: 8080 }; // number, not string\n// with NODE_USE_ENV_PROXY=1 -> TypeError: Invalid URL: 8080 on first request\n\n// after\nconst fakeEnv = { http_proxy: 'http://proxy.local:8080' };","handlingStrategy":"try-catch","validationCode":"// before enabling env-proxy or issuing the first request\nfunction proxyEnvTypesOk(env: Record<string, unknown>): boolean {\n  return ['http_proxy','HTTP_PROXY','https_proxy','HTTPS_PROXY']\n    .every((k) => env[k] === undefined || typeof env[k] === 'string');\n}","typeGuard":null,"tryCatchPattern":"try {\n  await doRequest();\n} catch (e) {\n  if (e instanceof TypeError && /^Invalid URL:/.test(e.message)) {\n    // broken proxy env: report config error clearly\n    console.error('proxy env var is not a string:', e.message);\n  } else throw e;\n}","preventionTips":["Keep proxy env values as strings in composed env objects","Run a smoke request after enabling NODE_USE_ENV_PROXY to fail fast","Note this class is a plain TypeError, not a coded Node error"],"tags":["proxy","env","config","node-compat"],"backgroundTag":null,"analyzedSha":"89f33cbef296a2b287f323d42de54c871fa69c77","analyzedAt":"2026-08-16T07:54:21.310Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}