{"record":{"id":"4bd7c04b0abd66fb","repo":"fish2018/pansou","slug":"w-4bd7c0","errorCode":null,"errorMessage":"代理地址解析失败: %w","messagePattern":"代理地址解析失败: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"util/http_util.go","lineNumber":84,"sourceCode":"\n\t// 创建客户端\n\tclient := &http.Client{\n\t\tTransport: transport,\n\t\tTimeout:   time.Duration(60) * time.Second,\n\t}\n\n\treturn client, nil\n}\n\nfunc applyProxy(transport *http.Transport, rawProxyURL string) error {\n\trawProxyURL = strings.TrimSpace(rawProxyURL)\n\tif rawProxyURL == \"\" {\n\t\treturn nil\n\t}\n\n\tproxyURL, err := url.Parse(rawProxyURL)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"代理地址解析失败: %w\", err)\n\t}\n\tif proxyURL.Scheme == \"\" || proxyURL.Host == \"\" {\n\t\treturn fmt.Errorf(\"代理地址必须包含协议和主机\")\n\t}\n\n\tswitch strings.ToLower(proxyURL.Scheme) {\n\tcase \"socks5\", \"socks5h\":\n\t\tif proxyURL.Scheme == \"socks5h\" {\n\t\t\tclone := *proxyURL\n\t\t\tclone.Scheme = \"socks5\"\n\t\t\tproxyURL = &clone\n\t\t}\n\n\t\t// 创建SOCKS5代理拨号器\n\t\tdialer, err := proxy.FromURL(proxyURL, proxy.Direct)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"SOCKS5代理初始化失败: %w\", err)\n\t\t}","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/fish2018/pansou/blob/beaa56133755a548ebc51b090b3816e2ae044aa6/util/http_util.go#L66-L102","documentation":"applyProxy validates the proxy URL passed to NewHTTPClient before configuring the HTTP transport. This error is returned when Go's url.Parse cannot parse the raw proxy string (e.g. malformed syntax like control characters or invalid percent-encoding). The original parse error is wrapped with %w so it can be inspected with errors.Is/As.","triggerScenarios":"Calling NewHTTPClient with a proxy option string that url.Parse rejects, e.g. 'http://[::1:8080' (malformed bracket), a URL containing raw spaces or control characters, or invalid percent-escapes like 'http://proxy:%zz@host'.","commonSituations":"Proxy read from an env var (HTTP_PROXY/HTTPS_PROXY) or config file with a stray space or invisible character; hand-edited YAML/JSON config with a truncated URL; interpolating credentials containing reserved characters without escaping.","solutions":["Print/inspect the raw proxy string (use %q) to spot hidden whitespace or bad characters and fix the value.","Validate the proxy with url.Parse in your own config-loading code before passing it to NewHTTPClient.","Escape credentials in the URL with url.UserPassword(username, password) instead of string concatenation.","If the proxy comes from an env var, trim whitespace: strings.TrimSpace(os.Getenv(\"HTTPS_PROXY\"))."],"exampleFix":"// before\nclient, err := NewHTTPClient(WithProxy(os.Getenv(\"HTTPS_PROXY\")))\n\n// after\nraw := strings.TrimSpace(os.Getenv(\"HTTPS_PROXY\"))\nif raw != \"\" {\n    if _, err := url.Parse(raw); err != nil {\n        return fmt.Errorf(\"invalid HTTPS_PROXY %q: %w\", raw, err)\n    }\n}\nclient, err := NewHTTPClient(WithProxy(raw))","handlingStrategy":"validation","validationCode":"raw := strings.TrimSpace(cfg.Proxy)\nif raw != \"\" {\n    if _, err := url.Parse(raw); err != nil {\n        return fmt.Errorf(\"invalid proxy URL %q: %w\", raw, err)\n    }\n}","typeGuard":null,"tryCatchPattern":"if err := NewHTTPClient(opts...); err != nil {\n    var perr *url.Error\n    if errors.As(err, &perr) {\n        // handle malformed proxy URL\n    }\n    return err\n}","preventionTips":["Always trim proxy values read from env vars or config files.","Store proxies in full 'scheme://host:port' form in configuration.","Validate proxy URLs at config-load time, not at request time."],"tags":["network","proxy","url-parse","configuration"],"backgroundTag":"invalid-url-format","analyzedSha":"beaa56133755a548ebc51b090b3816e2ae044aa6","analyzedAt":"2026-09-07T00:31:18.025Z","contentChangedAt":"2026-09-07T00:31:18.025Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}