{"record":{"id":"bbbdc37de35b4624","repo":"fish2018/pansou","slug":"socks5-w-bbbdc3","errorCode":null,"errorMessage":"SOCKS5代理初始化失败: %w","messagePattern":"SOCKS5代理初始化失败: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"util/http_util.go","lineNumber":101,"sourceCode":"\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}\n\n\t\ttransport.DialContext = func(ctx context.Context, network, addr string) (net.Conn, error) {\n\t\t\treturn dialer.Dial(network, addr)\n\t\t}\n\tcase \"http\", \"https\":\n\t\t// HTTP/HTTPS代理\n\t\ttransport.Proxy = http.ProxyURL(proxyURL)\n\tdefault:\n\t\treturn fmt.Errorf(\"不支持的代理协议: %s\", proxyURL.Scheme)\n\t}\n\n\treturn nil\n}\n\n// GetHTTPClient 获取HTTP客户端\nfunc GetHTTPClient() *http.Client {\n\tif httpClient == nil {","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/fish2018/pansou/blob/beaa56133755a548ebc51b090b3816e2ae044aa6/util/http_util.go#L83-L119","documentation":"For schemes 'socks5'/'socks5h', applyProxy builds a SOCKS5 dialer with golang.org/x/net/proxy's proxy.FromURL and wraps any failure. This error means the proxy library could not construct a dialer from the parsed URL, typically because the URL's authentication info is malformed or the scheme string is rejected by proxy.FromURL.","triggerScenarios":"NewHTTPClient called with a socks5 proxy URL whose user:password component cannot be used to build auth (e.g. URL-encoded credentials that fail to decode, or an unsupported scheme variant passed to proxy.FromURL).","commonSituations":"SOCKS5 proxies requiring auth where the password contains special characters not correctly encoded; using a scheme proxy.FromURL does not accept; a dependency version of golang.org/x/net whose FromURL rejects the URL form.","solutions":["Inspect the wrapped error (%w) for the underlying cause reported by proxy.FromURL.","Percent-encode the username/password in the SOCKS5 URL, e.g. use url.UserPassword or escape special characters: 'socks5://user:p%40ss@host:1080'.","Test the same URL with proxy.FromURL in isolation to confirm it is constructible.","Update golang.org/x/net to the latest version in go.mod."],"exampleFix":"// before\nclient, err := NewHTTPClient(WithProxy(\"socks5://user:p@ss:wrd@127.0.0.1:1080\"))\n\n// after\nclient, err := NewHTTPClient(WithProxy(\"socks5://user:p%40ss%3Awrd@127.0.0.1:1080\"))","handlingStrategy":"try-catch","validationCode":"if u, err := url.Parse(cfg.Proxy); err == nil && strings.HasPrefix(u.Scheme, \"socks5\") {\n    if _, err := proxy.FromURL(u, proxy.Direct); err != nil {\n        return fmt.Errorf(\"unusable SOCKS5 proxy: %w\", err)\n    }\n}","typeGuard":null,"tryCatchPattern":"if err := NewHTTPClient(WithProxy(socksURL)); err != nil {\n    var wrapped error\n    if errors.As(err, &wrapped) && strings.Contains(err.Error(), \"SOCKS5\") {\n        // inspect wrapped cause from proxy.FromURL, fix credentials/encoding\n    }\n    return err\n}","preventionTips":["Percent-encode usernames and passwords in SOCKS5 URLs.","Test SOCKS5 proxy URLs with proxy.FromURL before deploying config.","Keep golang.org/x/net up to date."],"tags":["network","proxy","socks5","initialization"],"backgroundTag":"network-request-failed","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"}