{"record":{"id":"8a724d7c46b9a93c","repo":"fish2018/pansou","slug":"w-8a724d","errorCode":null,"errorMessage":"创建请求失败: %w","messagePattern":"创建请求失败: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugin/cyg/cyg.go","lineNumber":140,"sourceCode":"\t// 3. 并发获取每个帖子的下载链接\n\tresults := p.fetchDownloadLinksAsync(client, posts, keyword)\n\n\t// 4. 关键词过滤\n\tfilteredResults := plugin.FilterResultsByKeyword(results, keyword)\n\n\treturn filteredResults, nil\n}\n\n// fetchSearchResults 获取搜索结果列表\nfunc (p *CygPlugin) fetchSearchResults(client *http.Client, searchURL string) ([]CygPost, error) {\n\t// 创建带超时的上下文\n\tctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)\n\tdefer cancel()\n\n\t// 创建请求对象\n\treq, err := http.NewRequestWithContext(ctx, \"GET\", searchURL, nil)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"创建请求失败: %w\", err)\n\t}\n\n\t// 设置请求头\n\tp.setRequestHeaders(req)\n\n\t// 发送请求\n\tresp, err := p.doRequestWithRetry(req, client)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"HTTP请求失败: %w\", err)\n\t}\n\tdefer resp.Body.Close()\n\n\t// 检查状态码\n\tif resp.StatusCode != 200 {\n\t\treturn nil, fmt.Errorf(\"HTTP错误状态码: %d\", resp.StatusCode)\n\t}\n\n\t// 解析响应","sourceCodeStart":122,"sourceCodeEnd":158,"githubUrl":"https://github.com/fish2018/pansou/blob/beaa56133755a548ebc51b090b3816e2ae044aa6/plugin/cyg/cyg.go#L122-L158","documentation":"In fetchSearchResults, http.NewRequestWithContext failed to construct the GET request for the search URL. This happens before any network I/O and usually means the URL is malformed (unparsable scheme/host) — often because keyword interpolation produced an invalid URL.","triggerScenarios":"searchImpl passes a searchURL built from cygBaseURL plus query params that http.NewRequestWithContext cannot parse — e.g. empty base URL, control characters in the keyword that survived QueryEscape, or a malformed base URL configuration.","commonSituations":"cygBaseURL configured without a scheme (missing https://) or with a typo; keyword containing newlines or control characters; empty configuration making the URL just the query string.","solutions":["Validate cygBaseURL starts with http:// or https:// and is a parseable URL before building the request.","Ensure url.QueryEscape is applied to the keyword (it is) and that no raw control characters enter the URL.","Print the final searchURL on failure to spot malformed construction.","Use url.Parse on the final URL as a pre-check and fail early with a clearer message."],"exampleFix":"// before\nreq, err := http.NewRequestWithContext(ctx, \"GET\", searchURL, nil)\nif err != nil {\n    return nil, fmt.Errorf(\"创建请求失败: %w\", err)\n}\n// after\nif u, perr := url.Parse(searchURL); perr != nil || u.Scheme == \"\" || u.Host == \"\" {\n    return nil, fmt.Errorf(\"无效的搜索URL: %q (%v)\", searchURL, perr)\n}\nreq, err := http.NewRequestWithContext(ctx, \"GET\", searchURL, nil)\nif err != nil {\n    return nil, fmt.Errorf(\"创建请求失败: %w\", err)\n}","handlingStrategy":"validation","validationCode":"u, err := url.Parse(baseURL)\nif err != nil || u.Scheme == \"\" || u.Host == \"\" {\n    return fmt.Errorf(\"cygBaseURL 无效: %q\", baseURL)\n}","typeGuard":null,"tryCatchPattern":"results, err := plugin.SearchWithResult(ctx, opts)\nif err != nil && strings.Contains(err.Error(), \"创建请求失败\") {\n    // configuration problem: check baseURL format before retrying\n}","preventionTips":["Validate the base URL (scheme + host) at config load time, not at request time","Reject empty or scheme-less URLs in configuration","Keep url.QueryEscape on all user-derived query values"],"tags":["http","url","request-construction","go"],"backgroundTag":"invalid-url","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"}