{"record":{"id":"a3240b3678d63be3","repo":"denoland/deno","slug":"err-invalid-arg-type-a3240b","errorCode":"ERR_INVALID_ARG_TYPE","errorMessage":"The \"proxyEnv\" argument must be an instance of Object. Received ${input}","messagePattern":"The \"proxyEnv\" argument must be an instance of Object\\. Received (.+?)","errorType":"exception","errorClass":"NodeTypeError","httpStatus":null,"severity":"error","filePath":"ext/node/polyfills/_http_proxy.js","lineNumber":393,"sourceCode":"  if (!enabled) return;\n  // Use \"env\" mode so an invalid HTTP_PROXY surfaces as TypeError: Invalid URL,\n  // matching Node v24's behavior at request time. The error propagates out\n  // through resolveAgentProxyConfig and surfaces on the offending request.\n  const cfg = buildProxyConfig(env, \"env\");\n  if (cfg) globalProxyConfig = cfg;\n}\n\nfunction getGlobalProxyConfig() {\n  maybeInitFromEnv();\n  return globalProxyConfig;\n}\n\nfunction setGlobalProxyFromEnv(input) {\n  let env;\n  if (input === undefined) {\n    env = readPrivilegedEnv();\n  } else if (!isPlainObject(input)) {\n    throw new ERR_INVALID_ARG_TYPE(\n      \"proxyEnv\",\n      \"Object\",\n      input,\n    );\n  } else {\n    env = input;\n  }\n  // Calling setGlobalProxyFromEnv replaces any NODE_USE_ENV_PROXY-derived\n  // state; ensure that read-once gate is closed.\n  try {\n    maybeInitFromEnv();\n  } catch {\n    // Env-derived init may throw on invalid URLs, but the explicit caller\n    // is replacing it anyway - swallow so we can install the new config.\n  }\n  initializedFromEnv = true;\n  const newConfig = buildProxyConfig(env, \"strict\");\n  const prev = globalProxyConfig;","sourceCodeStart":375,"sourceCodeEnd":411,"githubUrl":"https://github.com/denoland/deno/blob/89f33cbef296a2b287f323d42de54c871fa69c77/ext/node/polyfills/_http_proxy.js#L375-L411","documentation":"http.setGlobalProxyFromEnv(input) accepts either no argument (then it reads HTTP_PROXY/HTTPS_PROXY/NO_PROXY from the process environment) or a plain object of env-like values. Passing any defined non-object - array, string, number - throws ERR_INVALID_ARG_TYPE for 'proxyEnv'. Note null is also rejected here because isPlainObject(null) is false (unlike the Agent path, which tolerates null).","triggerScenarios":"http.setGlobalProxyFromEnv('http://proxy:8080') (passing a URL string), setGlobalProxyFromEnv(['http_proxy=x']) (array), or setGlobalProxyFromEnv(null).","commonSituations":"Assuming the API takes a URL; forwarding a possibly-null config field into the call.","solutions":["Pass a plain object: setGlobalProxyFromEnv({ http_proxy: 'http://proxy:8080' })","Call it with no argument to read the real process environment","Guard nullable config: `if (cfg) http.setGlobalProxyFromEnv(cfg)`"],"exampleFix":"// before\nhttp.setGlobalProxyFromEnv(proxyUrl); // string -> throws ERR_INVALID_ARG_TYPE\n\n// after\nhttp.setGlobalProxyFromEnv({ http_proxy: proxyUrl, https_proxy: proxyUrl });","handlingStrategy":"type-guard","validationCode":"function isPlainObject(v: unknown): v is Record<string, unknown> {\n  return !!v && typeof v === 'object' && !Array.isArray(v);\n}\nif (cfg === undefined) http.setGlobalProxyFromEnv();\nelse if (isPlainObject(cfg)) http.setGlobalProxyFromEnv(cfg as Record<string, string>);\nelse throw new Error('proxy config must be a plain object');","typeGuard":"function isProxyEnvObject(v: unknown): v is Record<string, string | undefined> {\n  return v === undefined || (!!v && typeof v === 'object' && !Array.isArray(v));\n}","tryCatchPattern":"try {\n  http.setGlobalProxyFromEnv(cfg);\n} catch (e) {\n  if (e?.code === 'ERR_INVALID_ARG_TYPE' && /proxyEnv/.test(e.message)) {\n    http.setGlobalProxyFromEnv({ https_proxy: String(cfg) }); // coerce single URL\n  } else throw e;\n}","preventionTips":["The API takes an env-shaped object ({http_proxy, https_proxy, no_proxy}), not a URL","Calling it with no argument reads the process environment - prefer that over passing process.env yourself","Guard nullable config before the call: null is rejected here"],"tags":["proxy","api-misuse","types","validation"],"backgroundTag":null,"analyzedSha":"89f33cbef296a2b287f323d42de54c871fa69c77","analyzedAt":"2026-08-16T07:54:21.310Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}