{"record":{"id":"e3a06a13c15fbff3","repo":"fish2018/pansou","slug":"w-e3a06a","errorCode":null,"errorMessage":"创建请求失败: %w","messagePattern":"创建请求失败: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugin/hdr4k/hdr4k.go","lineNumber":143,"sourceCode":"\t// 处理ext参数\n\tsearchKeyword := keyword\n\tif ext != nil {\n\t\t// 使用类型断言安全地获取参数\n\t\tif titleEn, ok := ext[\"title_en\"].(string); ok && titleEn != \"\" {\n\t\t\t// 使用英文标题替换关键词\n\t\t\tsearchKeyword = titleEn\n\t\t}\n\t}\n\t\n\t// 构建POST请求数据\n\tdata := url.Values{}\n\tdata.Set(\"srchtxt\", searchKeyword)\n\tdata.Set(\"searchsubmit\", \"yes\")\n\t\n\t// 发送POST请求\n\treq, err := http.NewRequest(\"POST\", SearchURL, strings.NewReader(data.Encode()))\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"创建请求失败: %w\", err)\n\t}\n\t\n\t// 设置请求头\n\treq.Header.Set(\"User-Agent\", getRandomUA())\n\treq.Header.Set(\"Content-Type\", \"application/x-www-form-urlencoded\")\n\treq.Header.Set(\"Referer\", \"https://www.4khdr.cn/\")\n\t\n\t// 发送请求（带重试）\n\tresp, err := p.doRequestWithRetry(client, req, MaxRetries)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"请求失败: %w\", err)\n\t}\n\tdefer resp.Body.Close()\n\t\n\t// 解析HTML\n\tdoc, err := goquery.NewDocumentFromReader(resp.Body)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"解析HTML失败: %w\", err)","sourceCodeStart":125,"sourceCodeEnd":161,"githubUrl":"https://github.com/fish2018/pansou/blob/beaa56133755a548ebc51b090b3816e2ae044aa6/plugin/hdr4k/hdr4k.go#L125-L161","documentation":"hdr4k's doSearch wraps errors from http.NewRequest as 创建请求失败. Building a POST request to the 4KHDR search endpoint failed — with a strings.NewReader body this essentially only happens if SearchURL is not a parseable absolute URL.","triggerScenarios":"http.NewRequest(\"POST\", SearchURL, ...) errors because SearchURL is empty, malformed, or contains invalid characters (spaces, unencoded CJK) — e.g. a misconfigured or corrupted constant.","commonSituations":"BaseURL/SearchURL constant edited incorrectly; config value with whitespace or wrong scheme; build-time templating producing an empty URL.","solutions":["Print SearchURL and fix any malformed characters or missing scheme","Validate with url.Parse(SearchURL) at plugin init so misconfiguration fails fast","URL-encode any dynamic parts of the URL instead of concatenating raw text","Restore the correct constant if it was accidentally changed"],"exampleFix":"// before\nreq, err := http.NewRequest(\"POST\", SearchURL, strings.NewReader(data.Encode()))\nif err != nil {\n    return nil, fmt.Errorf(\"创建请求失败: %w\", err)\n}\n// after\nif _, err := url.Parse(SearchURL); err != nil {\n    return nil, fmt.Errorf(\"配置的 SearchURL 无效 %q: %w\", SearchURL, err)\n}\nreq, err := http.NewRequest(\"POST\", SearchURL, strings.NewReader(data.Encode()))\nif err != nil {\n    return nil, fmt.Errorf(\"创建请求失败: %w\", err)\n}","handlingStrategy":"validation","validationCode":"// Go: fail fast on a misconfigured SearchURL\nif SearchURL == \"\" {\n    return nil, fmt.Errorf(\"SearchURL is not configured\")\n}\nif _, err := url.Parse(SearchURL); err != nil {\n    return nil, fmt.Errorf(\"SearchURL invalid: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"req, err := http.NewRequest(\"POST\", SearchURL, strings.NewReader(data.Encode()))\nif err != nil {\n    return nil, fmt.Errorf(\"创建请求失败: %w (SearchURL=%q)\", err, SearchURL)\n}","preventionTips":["Validate configured URLs once at startup, not per request","Keep URL constants free of whitespace/typos","Add a startup smoke test that builds each plugin's request"],"tags":["go","http","url","config"],"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"}