{"record":{"id":"fab3cea5b26a1684","repo":"fish2018/pansou","slug":"s-w-fab3ce","errorCode":null,"errorMessage":"[%s] 创建请求失败: %w","messagePattern":"\\[(.+?)\\] 创建请求失败: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugin/aikanzy/aikanzy.go","lineNumber":147,"sourceCode":"\t// 使用优化的客户端\n\tif p.optimizedClient != nil {\n\t\tclient = p.optimizedClient\n\t}\n\t\n\t// 对关键词进行URL编码\n\tencodedKeyword := url.QueryEscape(keyword)\n\t\n\t// 构建搜索URL\n\tsearchURL := fmt.Sprintf(searchURLTemplate, encodedKeyword)\n\t\n\t// 创建一个带有超时的上下文\n\tctx, cancel := context.WithTimeout(context.Background(), defaultTimeout*time.Second)\n\tdefer cancel()\n\t\n\t// 创建请求\n\treq, err := http.NewRequestWithContext(ctx, \"GET\", searchURL, nil)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"[%s] 创建请求失败: %w\", p.Name(), err)\n\t}\n\t\n\t// 设置完整的请求头（避免反爬虫）\n\treq.Header.Set(\"User-Agent\", \"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36\")\n\treq.Header.Set(\"Accept\", \"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8\")\n\treq.Header.Set(\"Accept-Language\", \"zh-CN,zh;q=0.9,en;q=0.8\")\n\treq.Header.Set(\"Connection\", \"keep-alive\")\n\treq.Header.Set(\"Referer\", \"https://www.aikanzy.com/\")\n\treq.Header.Set(\"Upgrade-Insecure-Requests\", \"1\")\n\treq.Header.Set(\"Cache-Control\", \"max-age=0\")\n\t\n\t// 使用带重试的请求方法发送HTTP请求\n\tresp, err := p.doRequestWithRetry(req, client)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"[%s] 请求搜索页面失败: %w\", p.Name(), err)\n\t}\n\tdefer resp.Body.Close()\n\t","sourceCodeStart":129,"sourceCodeEnd":165,"githubUrl":"https://github.com/fish2018/pansou/blob/beaa56133755a548ebc51b090b3816e2ae044aa6/plugin/aikanzy/aikanzy.go#L129-L165","documentation":"Returned by doSearch in the aikanzy plugin when http.NewRequestWithContext fails to construct the GET request for the search URL. This happens before any network I/O and almost always means the URL string is malformed (parse error), since method/body are constant. The construction error is wrapped with %w.","triggerScenarios":"p.doSearch builds searchURL (base URL + query params) and passes it to http.NewRequestWithContext; http.NewRequest returns an error because the URL cannot be parsed (e.g. control characters, bad scheme, unescaped invalid chars from user keyword interpolation).","commonSituations":"The configured base URL has a typo (missing scheme like 'https://'); the search keyword contains characters that were not url.QueryEscape'd; an env/config override sets an empty or invalid URL.","solutions":["Log/print the searchURL on failure to spot the malformed URL.","Ensure the base URL includes a valid scheme (https://) and host.","Escape the keyword with url.QueryEscape before appending it to the URL.","Validate the final URL with url.Parse before calling http.NewRequestWithContext."],"exampleFix":"// before\nsearchURL := baseURL + \"/search/\" + keyword\nreq, err := http.NewRequestWithContext(ctx, \"GET\", searchURL, nil)\n// after\nsearchURL := baseURL + \"/search/\" + url.QueryEscape(keyword)\nif _, perr := neturl.Parse(searchURL); perr != nil {\n\treturn nil, fmt.Errorf(\"invalid search URL %q: %w\", searchURL, perr)\n}\nreq, err := http.NewRequestWithContext(ctx, \"GET\", searchURL, nil)","handlingStrategy":"validation","validationCode":"u, err := neturl.Parse(searchURL)\nif err != nil || u.Scheme == \"\" || u.Host == \"\" {\n\treturn fmt.Errorf(\"invalid search URL: %q\", searchURL)\n}\n// ensure keyword is escaped: url.QueryEscape(keyword)","typeGuard":null,"tryCatchPattern":"req, err := http.NewRequestWithContext(ctx, \"GET\", searchURL, nil)\nif err != nil {\n\tlog.Printf(\"request build failed for URL %q: %v\", searchURL, err)\n\treturn err\n}","preventionTips":["Always validate configured base URLs (scheme + host) at startup.","Use url.Values or url.QueryEscape for all user-supplied query terms.","Reject empty/whitespace keywords before building the URL.","Unit-test URL construction with special characters (%, &, spaces, CJK)."],"tags":["http-client","invalid-url","go"],"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"}