{"record":{"id":"c9b087feca67fb73","repo":"fish2018/pansou","slug":"socks5-w","errorCode":null,"errorMessage":"创建SOCKS5代理失败: %w","messagePattern":"创建SOCKS5代理失败: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugin/dy4k/dy4k.go","lineNumber":153,"sourceCode":"\t\tMaxIdleConns:        MaxIdleConns,\n\t\tMaxIdleConnsPerHost: MaxIdleConnsPerHost,\n\t\tMaxConnsPerHost:     MaxConnsPerHost,\n\t\tIdleConnTimeout:     IdleConnTimeout,\n\t\tDisableKeepAlives:   false,\n\t\tDisableCompression:  false,\n\t\tWriteBufferSize:     16 * 1024,\n\t\tReadBufferSize:      16 * 1024,\n\t}\n\n\tif proxyURL == \"\" {\n\t\treturn transport, nil\n\t}\n\n\tif strings.HasPrefix(proxyURL, \"socks5://\") {\n\t\t// SOCKS5代理\n\t\tdialer, err := proxy.SOCKS5(\"tcp\", strings.TrimPrefix(proxyURL, \"socks5://\"), nil, proxy.Direct)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"创建SOCKS5代理失败: %w\", err)\n\t\t}\n\t\ttransport.Dial = dialer.Dial\n\t\tdebugPrintf(\"🔧 [Dy4k DEBUG] 使用SOCKS5代理: %s\\n\", proxyURL)\n\t} else {\n\t\t// HTTP代理\n\t\tparsedURL, err := url.Parse(proxyURL)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"解析代理URL失败: %w\", err)\n\t\t}\n\t\ttransport.Proxy = http.ProxyURL(parsedURL)\n\t\tdebugPrintf(\"🔧 [Dy4k DEBUG] 使用HTTP代理: %s\\n\", proxyURL)\n\t}\n\n\treturn transport, nil\n}\n\n// createOptimizedHTTPClient 创建优化的HTTP客户端（支持代理）\nfunc createOptimizedHTTPClient() *http.Client {","sourceCodeStart":135,"sourceCodeEnd":171,"githubUrl":"https://github.com/fish2018/pansou/blob/beaa56133755a548ebc51b090b3816e2ae044aa6/plugin/dy4k/dy4k.go#L135-L171","documentation":"In dy4k's createProxyTransport, golang.org/x/net/proxy.SOCKS5 failed to construct a SOCKS5 dialer from the configured socks5:// proxy address, so the function returns the wrapped error. This happens before any connection is attempted — it is a dialer-construction failure, almost always due to a malformed address string.","triggerScenarios":"proxyURL starts with socks5:// but the remainder after TrimPrefix is not a valid host:port (missing port, hostname with no port, extra scheme characters, or embedded whitespace), causing net.Dial's address parsing inside proxy.SOCKS5 to fail.","commonSituations":"Proxy configured as socks5://127.0.0.1 (no port) or socks5://user:pass@host:1080 where credentials are embedded in the address and not stripped; typo in the proxy env/config value; empty proxy string that still matches the prefix by mistake.","solutions":["Log/verify proxyURL; ensure it is exactly host:port after stripping socks5:// (e.g. 127.0.0.1:1080).","Strip any userinfo before passing to proxy.SOCKS5; if auth is needed, pass it via the *proxy.Auth parameter instead of embedding it in the address.","Parse the proxy with net.SplitHostPort first and fail fast with a clear config error if it doesn't split.","Fix the proxy configuration value in the environment/config file."],"exampleFix":"// before\ndialer, err := proxy.SOCKS5(\"tcp\", strings.TrimPrefix(proxyURL, \"socks5://\"), nil, proxy.Direct)\nif err != nil {\n    return nil, fmt.Errorf(\"创建SOCKS5代理失败: %w\", err)\n}\n// after\naddr := strings.TrimPrefix(proxyURL, \"socks5://\")\nif _, _, serr := net.SplitHostPort(addr); serr != nil {\n    return nil, fmt.Errorf(\"SOCKS5代理地址缺少端口: %q\", proxyURL)\n}\ndialer, err := proxy.SOCKS5(\"tcp\", addr, nil, proxy.Direct)\nif err != nil {\n    return nil, fmt.Errorf(\"创建SOCKS5代理失败: %w\", err)\n}","handlingStrategy":"validation","validationCode":"addr := strings.TrimPrefix(proxyURL, \"socks5://\")\nif err := validateProxyAddr(addr); err != nil {\n    return fmt.Errorf(\"bad socks5 proxy %q: %w\", proxyURL, err)\n}\nfunc validateProxyAddr(addr string) error {\n    host, port, err := net.SplitHostPort(addr)\n    if err != nil { return err }\n    if host == \"\" || port == \"\" { return fmt.Errorf(\"empty host or port\") }\n    return nil\n}","typeGuard":"func isSocks5Addr(s string) bool {\n    _, _, err := net.SplitHostPort(strings.TrimPrefix(s, \"socks5://\"))\n    return err == nil\n}","tryCatchPattern":null,"preventionTips":["Validate proxy settings at startup, not per-request.","Never embed user:pass in a SOCKS5 address; use proxy.Auth.","Document the expected host:port format in config samples.","Test the proxy with a real dial in a health check."],"tags":["proxy","socks5","config","network"],"backgroundTag":"invalid-config-value","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"}