{"record":{"id":"a4d8cb0561f0a85d","repo":"yikart/AiToEarn","slug":"error-a4d8cb","errorCode":null,"errorMessage":"代理地址不合法","messagePattern":"代理地址不合法","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"project/aitoearn-electron/electron/plat/requestNet.ts","lineNumber":46,"sourceCode":"  headers,\n  body,\n  method,\n  url,\n  isFile,\n  formData,\n  isReqFile,\n  proxy,\n}: IRequestNetParams): Promise<IRequestNetResult<T>> => {\n  let customSession: Session;\n  let proxyInfo: ProxyInfo | false;\n  return new Promise(async (resolve, reject) => {\n    try {\n      // 如果传入了代理配置，动态设置代理\n      if (proxy) {\n        // 解析代理信息\n        proxyInfo = parseProxyString(proxy);\n        if (proxyInfo === false || !ipv4Regular.test(proxyInfo.ipAndPort))\n          throw new Error('代理地址不合法');\n        customSession = session.fromPartition(\n          `persist:proxy-session-${Date.now()}`,\n        );\n        const proxyUrl = `${proxyInfo.protocol}://${proxyInfo.ipAndPort}`;\n        const proxyRules = `http=${proxyUrl};https=${proxyUrl}`;\n        console.log(proxyRules);\n        await customSession.setProxy({\n          proxyRules,\n        });\n\n        headers = {\n          ...(headers ? headers : {}),\n          ...(proxy\n            ? {\n                'x-forwarded-for': proxyInfo.ipAndPort,\n              }\n            : {}),\n        };","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/yikart/AiToEarn/blob/d3aa8bea5b146a8675607cf0144d891aad3e9683/project/aitoearn-electron/electron/plat/requestNet.ts#L28-L64","documentation":"requestNet validates any proxy string passed in its options. The proxy string is parsed with parseProxyString and the resulting ipAndPort must match the ipv4Regular IPv4 regex; if parsing fails (returns false) or the address is not a valid IPv4:port, this Error is thrown. The library only supports IPv4 proxy addresses, not hostnames or IPv6.","triggerScenarios":"Calling requestNet (or any platform service that forwards a proxy option, e.g. Douyin/Shipinhao publish flows) with proxy set to a malformed string like 'http=proxy.com:8080' (hostname), an IPv6 address, a missing port, or an unparseable format.","commonSituations":"Users entering a proxy hostname (e.g. proxy.example.com:8080) instead of an IP, copying a proxy URL with scheme/path into the ip:port field, IPv6 proxies, or empty/garbage values in proxy config UI.","solutions":["Use a numeric IPv4 address with port, e.g. '127.0.0.1:7890' or '192.168.1.10:8080'.","Check the string format parseProxyString expects (protocol + ip:port, optionally user:pass) and match it exactly.","Remove the proxy option entirely if no proxy is needed — validation only runs when proxy is truthy.","Pre-validate the proxy with the ipv4Regular regex before passing it to requestNet."],"exampleFix":"// before\nawait requestNet({ url, proxy: 'http://proxy.corp.local:8080' });\n// after\nconst proxy = 'http://10.0.0.8:8080'; // must be IPv4 ip:port\nif (!ipv4Regular.test(proxy)) throw new Error('proxy must be ipv4:port');\nawait requestNet({ url, proxy });","handlingStrategy":"validation","validationCode":"import { ipv4Regular } from './commont/regular';\nfunction isProxyValid(proxy?: string): boolean {\n  if (!proxy) return true; // no proxy is fine\n  const m = proxy.match(/^(\\w+:\\/\\/)?([^/?]+)$/);\n  return !!m && ipv4Regular.test(m[2]);\n}\nif (!isProxyValid(proxy)) throw new Error('proxy must be ipv4:port');","typeGuard":"function parseProxySafe(proxy: string): ProxyInfo | null {\n  const info = parseProxyString(proxy);\n  return info === false ? null : info;\n}","tryCatchPattern":"try {\n  await requestNet({ url, proxy });\n} catch (e) {\n  if (e.message === '代理地址不合法') {\n    // prompt user to enter a valid ipv4:port proxy\n  }\n}","preventionTips":["Always store proxies as ipv4:port, never hostnames or URLs","Pre-validate with the ipv4Regular regex at config entry (UI/form layer)","Omit the proxy field entirely when no proxy is needed","Document that IPv6 and DNS-name proxies are unsupported"],"tags":["proxy","validation","network","configuration"],"backgroundTag":"invalid-proxy-address","analyzedSha":"d3aa8bea5b146a8675607cf0144d891aad3e9683","analyzedAt":"2026-08-31T14:19:24.185Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}