{"record":{"id":"caf9e924e5921656","repo":"fish2018/pansou","slug":"s-w-caf9e9","errorCode":null,"errorMessage":"[%s] 创建请求失败: %w","messagePattern":"\\[(.+?)\\] 创建请求失败: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugin/cldi/cldi.go","lineNumber":136,"sourceCode":"\t}\n\n\t// 3. 关键词过滤\n\treturn plugin.FilterResultsByKeyword(allResults, keyword), nil\n}\n\n// searchPage 搜索指定页面\nfunc (p *CldiPlugin) searchPage(client *http.Client, keyword string, page int) ([]model.SearchResult, error) {\n\t// 构建搜索URL (分类=0全部, 排序=2按添加时间)\n\tsearchURL := fmt.Sprintf(\"%s/search-%s-0-2-%d.html\", baseURL, url.QueryEscape(keyword), page)\n\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(\"[%s] 创建请求失败: %w\", p.Name(), 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(\"[%s] 搜索请求失败: %w\", p.Name(), err)\n\t}\n\tdefer resp.Body.Close()\n\n\t// 检查状态码\n\tif resp.StatusCode != 200 {\n\t\treturn nil, fmt.Errorf(\"[%s] 请求返回状态码: %d\", p.Name(), resp.StatusCode)\n\t}\n\n\t// 读取响应","sourceCodeStart":118,"sourceCodeEnd":154,"githubUrl":"https://github.com/fish2018/pansou/blob/beaa56133755a548ebc51b090b3816e2ae044aa6/plugin/cldi/cldi.go#L118-L154","documentation":"CldiPlugin.searchPage wraps http.NewRequestWithContext failures with the plugin name. This error is rare in practice: it fires only when the method/URL are syntactically invalid or the context is nil, since a malformed URL cannot be parsed into a *http.Request.","triggerScenarios":"http.NewRequestWithContext(ctx, \"GET\", searchURL, nil) returns err — searchURL is malformed (bad scheme, invalid characters, unparsable host) in searchPage.","commonSituations":"Configuration supplying a wrong or partially-updated base URL (e.g. missing scheme, spaces, or CJK characters not escaped), or a corrupted plugin config value.","solutions":["Log/print searchURL and validate it with url.Parse before constructing the request.","Ensure the base URL includes a scheme (https://) and is properly URL-escaped.","Fix the plugin config value holding the endpoint URL."],"exampleFix":"// before\nreq, err := http.NewRequestWithContext(ctx, \"GET\", searchURL, nil)\nif err != nil {\n    return nil, fmt.Errorf(\"[%s] 创建请求失败: %w\", p.Name(), err)\n}\n// after\nu, perr := url.Parse(searchURL)\nif perr != nil {\n    return nil, fmt.Errorf(\"[%s] 无效搜索URL %q: %w\", p.Name(), searchURL, perr)\n}\nreq, err := http.NewRequestWithContext(ctx, \"GET\", u.String(), nil)\nif err != nil {\n    return nil, fmt.Errorf(\"[%s] 创建请求失败: %w\", p.Name(), err)\n}","handlingStrategy":"validation","validationCode":"u, err := url.Parse(searchURL)\nif err != nil || u.Scheme == \"\" || u.Host == \"\" {\n    return fmt.Errorf(\"无效搜索URL: %q\", searchURL)\n}","typeGuard":"func isValidURL(raw string) bool {\n    u, err := url.Parse(raw)\n    return err == nil && (u.Scheme == \"http\" || u.Scheme == \"https\") && u.Host != \"\"\n}","tryCatchPattern":"results, err := plugin.Search(ctx, keyword)\nif err != nil {\n    if strings.Contains(err.Error(), \"创建请求失败\") {\n        // config bug: log the URL and disable this plugin rather than retrying\n    }\n}","preventionTips":["Validate configured base URLs at plugin init time with url.Parse","URL-escape keyword parameters before building the search URL","Always include the scheme in configured endpoints","Fail fast at startup if a plugin's endpoint is malformed"],"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"}